Linto davis
Linto davis

Reputation: 752

Regular expression for checking any word of at least one letter

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

Answers (5)

ghostdog74
ghostdog74

Reputation: 342313

you can use PHP functions as well

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

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798536

preg_match('/[a-z]/i', $s);

Upvotes: 1

Pavunkumar
Pavunkumar

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

cletus
cletus

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

vava
vava

Reputation: 25371

/a-zA-Z/

that's it

Upvotes: 0

Related Questions