How do you validate textbox value using javascript

Posted by Bravi under JavaScript on 9/25/2009 | Views : 4494 | Status : [Member] | Replies : 2
How do you validate textbox value whether it is number or string using javascript




Responses

Posted by: Raja on: 9/25/2009 [Member] Starter

Up
0
Down
You can get idea from below posts

http://www.dotnetfunda.com/codes/code158-how-to-validate-a-value-against-a-regular-expression-in-client-side-j.aspx

For JavaScript regular expression, see this link

http://www.rgagnon.com/jsdetails/js-0063.html

Thanks

Regards,
Raja, USA

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/28/2009 [Member] [MVP] Bronze

Up
0
Down
Hey,

I would recommend sticking to development best practices and use the asp.net validation framework.

You can use a regular expression to do the actual validation. There are lots of regex's available at this site:

http://www.regexlib.com/

You can plug this in to a RegularExpressionValidator which includes support out of the box for client side (javascript) and server side validation.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.regularexpressionvalidator.aspx

Remember - if you only validate on the client side then you are leaving a hole in your application. A user could have javascript turned off and then bad data could be passed in to your database. By checking on the client side first you get a nice user experience and then checking on the server side after you get security.

As for your specific validation request you have to be very clear so that we can help you build a working regex to meet your needs. Are you saying you want to allow any amount of letters and numbers but no other characters? Please give some examples of valid inputs and some examples of inputs you would like to block.

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response