Hamlets666 Posted December 15, 2006 Share Posted December 15, 2006 [code]$name = "test";if(!preg_match("[a-z]", $name)) { echo "BAD";} else { echo "GOOD";}[/code]But is show`s [b]BAD[/b], am I doing something wrong? Quote Link to comment Share on other sites More sharing options...
taith Posted December 15, 2006 Share Posted December 15, 2006 [code]$name = "test";if(is_nan($name)) echo "GOOD";else echo "BAD";[/code] Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted December 15, 2006 Share Posted December 15, 2006 Your regular expression will match only a single character from a-z as it is written.[b]Match any number of lower case alpha chars, including none:[/b]"/^[a-z]*$/"[b]Match any number of lower case alpha chars, at least one:[/b]"/^[a-z]+$/"[b]Match at most [i]n[/i] lower case alpha chars, including none:[/b]"/^[a-z]{[i]n[/i]}$/"[b]Match between [i]m[/i] and [i]n[/i] lower case alpha chars:[/b]"/^[a-z]{[i]m[/i],[i]n[/i]}$/"If you want to learn more:http://www.regular-expressions.info/tutorial.html Quote Link to comment Share on other sites More sharing options...
alpine Posted December 15, 2006 Share Posted December 15, 2006 example:[code]<?phpfunction Is_Chars($string){if(preg_match("/^[a-zA-Z]+$/", $string))return true;elsereturn false;}// exampleif(Is_Chars($_GET['value'])){ echo "Value is chars only";}else{ echo "Not only chars in the value";}?>[/code]And [color=red]is_nan()[/color] is not a way to check if it is chars only but rather to see if the value is not a numberhttp://no.php.net/manual/en/function.is-nan.php Quote Link to comment Share on other sites More sharing options...
SharkBait Posted December 15, 2006 Share Posted December 15, 2006 So [code=php:0]is_nan()[/code] is like the opposite of [code=php:0]is_numeric()[/code] ?Though [code=php:0]is_numeric()[/code] will be true against Hexidecimal numbers which or numeric strings which I guess isn't what is being looked for :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.