0

Hello Everyone,

Can you please give me some advise on how to validate input or select based on the class used?

For example: <input id="name" type="text" class="alphanumeric" value="">

Then for the validation:

if input class = "alphanumeric"
if !isAlphaNumeric(input.value)
alert(Enter valid value);input.focus

Before, I used onblur on the input to call the validator but it keeps prompting when I tried to out focus the input and I need to refresh the page.

Looking forward to your replies.

Thanks in advance

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by stbuchok
0

I would actually use a custom attribute (the convention is data-attributename for custom attributes). For example:

<input type="text" id="txtPassword" data-validationtype="password" />

You can then quite easily use jQuery to setup the events for validating.

$(function(){
    $('input[data-validationtype="password"').bind('onblur', function(){
        //code to validate passwords
    });

    $('input[data-validationtype="numeric"').bind('onblur', function(){
        //code to if the value entered is numeric
    });

//more types of validation
...

});

...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.