accept only string in textbox

General discussions related to php

Moderators: macek, egami, gesf

Gamers
New php-forum User
New php-forum User
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

accept only string in textbox

Postby Gamers » Mon Dec 10, 2012 10:24 am

Hi All,

I am creating a form, in this form i want user to enter only string in the text box for that can i create a funtion in php which check the value of the text box Or is there is any other alternative to limit the user to enter only string in the text box.

Thanks in advance

rstoll
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Dec 02, 2012 12:10 pm

Re: accept only string in textbox

Postby rstoll » Mon Dec 10, 2012 2:42 pm

You could use javascript to restrict the data. If you use jquery than have a look at:
http://docs.jquery.com/Plugins/Validation

However, you should also do a server side validation. You could use preg_match to check if the data conforms:
http://php.net/manual/en/function.preg-match.php

preg_match('#[a-zA-Z]#', $input);


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest