How to validate input box for only text input using jquery and php e.g name _ must accept only text input and no special character like "aaa@ or @@@ aaaa" and alpha numeric like "aaa123"
-
1with javascript or with php ? – safarov Apr 02 '12 at 08:50
3 Answers
You will want to use regular expressions I think. Take a look at this question which is pretty much the same as yours (except that it isnt about jquery) with PHP and all..
edit: Or as ComFreek points out, you can use the ctype_alnum function!
edit 2 ctype_alpha is actually what you are looking for; all alphabetic characters.
Checks if all of the characters in the provided string, text, are alphabetic. In the standard C locale letters are just [A-Za-z] and ctype_alpha() is equivalent to (ctype_upper($text) || ctype_lower($text)) if $text is just a single character, but other languages have letters that are considered neither upper nor lower case.
-
1I think regular expressions are a bit overkilled here, you could use [ctype_alnum](http://php.net/manual/en/function.ctype-alnum.php) – ComFreek Apr 02 '12 at 08:56
-
-
Ideally you want both jquery and php validation, jquery for a better user experience and php for data integrity.

- 3,802
- 3
- 32
- 51
regarding to this, you must look into the ascii table... A-Z is representing 65-90
you just need to detect the value that return when onkeyup in html...

- 700
- 2
- 14
- 24