This may be very simple, but how can i check, whether a user's name (firstname or lastname) is valid or not? A user's name should contain only alphabets
What could be the Regular Expression for Validating a user's name?
Collapse
X
-
Tags: None
-
Originally posted by rizwan6febThis may be very simple, but how can i check, whether a user's name (firstname or lastname) is valid or not? A user's name should contain only alphabets
In your case it is[php]if (preg_match("/^[a-zA-Z]+$/", $user_name))
{
//matching
}
else
{
//not matching
}[/php]
Regular Expression Details -
Originally posted by vikas1111Hi
Also check for blank space entry.. Instead of name i can enter blank space also,, Checking for only alphabets woth work properly..
Good luck,
DanComment
-
Originally posted by dlite922Just Use Trim() and check to see if its blank if its not blank, then check it against the regex [a-zA-Z\s?]+
Good luck,
Dan
trim — Strip whitespace (or other characters) from the beginning and end of a string
[php]
if(preg_match('/[^a-zA-Z]/', $string)
{
// bad name
}
else
{
// good name
}
[/php]
Should do it.Comment
Comment