Reputation: 752
Regular expression for checking any word of at least one letter
examples:
fish (right)
fish12 (right)
123 (wrong)
T (right)
12n(right)
Upvotes: 1
Views: 1545
Reputation: 342313
you can use PHP functions as well
if( strlen($string)>1 && ctype_alnum($string) ){
print "ok\n";
}
Upvotes: 0
Reputation: 5335
use preg_match function
$str ="1234a"; if ( preg_match ( '/[A-Za-z]{1,}/',$str ,$val ) ) { print "right" ; print_r ( $val ) ; } else { print "wrong " ; }
It prints right;
Upvotes: 1
Reputation: 625037
If you're inputting a word at a time then simply check:
[a-zA-Z]
because if you find a letter it's a word. If you have a stream of words it gets a little more difficult.
To find words that contain at least one letter:
\b([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*)\b
Upvotes: 3