tags:

views:

47

answers:

5

Regular expression for checking any word of at least one letter

examples:

fish (right)
fish12 (right)
123 (wrong)
T (right)
12n(right)

A: 
/a-zA-Z/

that's it

vava
+3  A: 

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
cletus
yes, its right, thank you very much
Linto davis
+1  A: 

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;

pavun_cool
+1  A: 
preg_match('/[a-z]/i', $s);
Ignacio Vazquez-Abrams
A: 

you can use PHP functions as well

if( strlen($string)>1 && ctype_alnum($string) ){
  print "ok\n";
}
ghostdog74