Hi, I am trying to check validy of an input (one word or more with spaces or - between the words) A word is more than one character The following code doesn't work...
<?php
$firstname = "Any String"; $first_name_valid=ereg("[A-Za-z]{1,}[ ]{*}[-A-Za-z]{*}", $firstname); if ($first_name_valid) { echo "True"; } else { echo "Wrong"; }
?>
Thanks for any help
if(strlen($string) > 1) { if(eregi("[^a-z |-]", $string)) { echo "Invalid Characters found"; } else { echo "Valid"; } } else { echo "Must be at least 2 characters"; }
Thanks but your solution isn't exactly what i am looking for.
The first character can't be a space, the space or - can come only between words.
Also, can you tell me what is wrong with my regular expression (for learning purposes)?
Thanks S
$valid = strlen($string) > 1 and preg_match('%^[a-z]+[a-z -]*$%i', $string);
give this a try
if the string must not end with space or comma simply copy&paste the [a-z]+ just before the $