Jump to content

texting box only allow numbers


prezident

Recommended Posts

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

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';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.