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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.