prezident Posted December 11, 2010 Share Posted December 11, 2010 if (preg_match($fname [0-9])) { echo "invalid FirstName"; } want the user to only be able to enter letters this is the code i have assuming that preg_match will spot any number in the $fname field and print "invalid firstname" if the user entered a number. how can i get the users to only insert letters? Link to comment https://forums.phpfreaks.com/topic/221303-texting-box-only-allow-numbers/ Share on other sites More sharing options...
vodos Posted December 11, 2010 Share Posted December 11, 2010 try with this code <? $word="v123odos"; if(ereg("^[a-z]$",$word)) echo "ok"; ?> Link to comment https://forums.phpfreaks.com/topic/221303-texting-box-only-allow-numbers/#findComment-1145680 Share on other sites More sharing options...
MMDE Posted December 11, 2010 Share Posted December 11, 2010 oh and the thread title is exactly the opposite of what you want, right? o.O if(preg_match('/^[a-zA-Z]{4,32}$/D',$usrname)){ echo 'There\'s only letters in the word '.$username.' and it\'s between 4 and 32 characters'; } I took the liberty to add a length limit too, should be pretty easy to spot how to edit it. If you want to remove it, just remove: {4,32} If you want it to be possible to have numbers and space too: if(preg_match('/^[a-zA-Z]{4,32}$/D',$usrname)){ echo 'There\'s only letters, numbers and spaces in the word '.$username.' and it\'s between 4 and 32 characters'; } Link to comment https://forums.phpfreaks.com/topic/221303-texting-box-only-allow-numbers/#findComment-1145704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.