-4

I want to validate a username as the user is typing according. The validation requirements are:

  1. no whitespace;
  2. no special characters;
  3. within a defined minimum and maximum length; and
  4. not the same as an existing username.

How do I do this using jQuery and ASP.NET?

Jordan Gray
  • 16,306
  • 3
  • 53
  • 69
Nikhil Chavan
  • 1,685
  • 2
  • 20
  • 34

1 Answers1

0

Try this:

$("input[type=textbox]").keydown(function(){
    if(/^[a-zA-Z0-9- ]*$/.test($(this).val()) == false) {
        alert('Your search string contains illegal characters.');
    }
    if(/\s/g.test($(this).val()) {
        alert("has white-space");
    }
    if(!$(this).val().length >= 8 && !$(this).val().length <= 25) {
        alert("out of range");
    }
});

For the fourth one you need to do it yourself because I don't have access to your field names etc.

Mohammad Areeb Siddiqui
  • 9,795
  • 14
  • 71
  • 113