Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
111
rated 0 times [  113] [ 2]  / answers: 1 / hits: 23596  / 13 Years ago, wed, july 27, 2011, 12:00:00

I am doing a street Address validation, in stret address validation text field should allow all the characters and Special characters.



To allow all the special characters, I have used the following way.
Is there a better way to allow all the special characters?



function isAcceptedChar_StAddress(s)
{
if (s == ',' || s == '#' || s == '-' || s == '/' || s == ||
s == '!' || s == '@' || s == '$' || s == % || s == '^' ||
s == '*' || s == '(' || s == ) || s == { || s == '}' ||
s == '|' || s == '[' || s == ] || s == \)
{
return true;
}
else
{
return false;
}
}


In the above code, i am comparing each character if it is matching I am returning true, else return false


More From » javascript

 Answers
17

If you want a function for this, try:



function validCharForStreetAddress(c) {
return ,#-/ !@$%^*(){}|[]\.indexOf(c) >= 0;
}

[#90985] Tuesday, July 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cullenmaxl

Total Points: 414
Total Questions: 112
Total Answers: 87

Location: United States Minor Outlying Island
Member since Sat, May 28, 2022
2 Years ago
;