2

I am looking for a jquery plugin that I can use with input textboxes to allowing only numeric input, alphanumeric input etc by the user?

I have been looking on google etc but looking for recommendations of such plugins.

amateur
  • 43,371
  • 65
  • 192
  • 320
  • 1
    JQuery has validation built in - it would be helpful to know in which ways it's unsuitable for you? – rlb.usa Aug 01 '11 at 21:59

3 Answers3

2

Test each of the following to make sure it's behavior is what you are expecting, because each might have slightly different behavior and setting options. Choose the one as per you requirements.

  1. Use the jquery Masked input plugin
  2. meioMask - another masked input jquery plugin
  3. JQUERY REGEX MASK PLUGIN
  4. All other masking plugins for jquery

I like the REGEX mask plugin, as you are in total control of masking capabilities and all it matters is how you come up with the regex (suggest using RegexBuddy)

Vin
  • 6,115
  • 4
  • 41
  • 55
0

Seems like you are looking for an answer explaining why it is not secure to validate in client-side. So, yes you can use any validation plugin as commented by @rlb.usa. But that is easily hackable by disabling javascript, so you want another validation in the server side e.g. php

Eric Fortis
  • 16,372
  • 6
  • 41
  • 62
0

here is a simple way to filter input as someone types in order to let them know they can only enter valid characters.....

$('input').bind('keyup',function(){$(this).val( String( $(this).val() ).replace(/[^a-z0-9]/gi,"")) });

Hope this is what you were looking for.

It uses jQuery, but it is not a plug-in.

By using the replace regular expression, it only allows users to input letters (A-z) and number (0-9).

If you need it to preserve spaces, you could use this:

$('input').bind('keyup',function(){$(this).val( String( $(this).val() ).replace(/[^a-z0-9\s]/gi,"")) });

If you are worried about validating your inputs, it is always a good idea to try and filter the user input at the source (your web page) as well as filter it on the server-side using something like PHP, CGI, etc.... That way, even if they generate the POST or GET HTTPrequest then they cannot override your server-side validation.

exoboy
  • 2,040
  • 2
  • 21
  • 29