Computer Science Canada Vaidating form input with PHP, for text only field |
Author: | peterggmss [ Thu Feb 14, 2008 2:25 pm ] | ||||
Post subject: | Vaidating form input with PHP, for text only field | ||||
I need to know how to check if a variable contains text. I need it to contain only text and no numbers, but I can't figure out how with only PHP. I have
and use
But I can't use is_string() for the text fields ($surname and $first_name) because if it contains numbers it will still validate as TRUE (1). Any advice? Thanks! |
Author: | md [ Thu Feb 14, 2008 3:04 pm ] |
Post subject: | RE:Vaidating form input with PHP, for text only field |
you could always make a function that steps through a string and makes sure each character contains a letter... 'tis not a very difficult function to write either. |
Author: | PaulButler [ Thu Feb 14, 2008 4:17 pm ] | ||
Post subject: | RE:Vaidating form input with PHP, for text only field | ||
Regular expressions will do the trick:
|
Author: | Brightguy [ Sun Mar 16, 2008 3:58 am ] |
Post subject: | Re: Vaidating form input with PHP, for text only field |
ctype_alpha($text) returns true if every character in $text is alphabetic. |