1

I want to validate dynamic textbox using jquery.Textbox value should contain alphanumeric value and it should allow special characters Underscore(_).In my scenario i have two textbox such as eg.. Name and PhoneNumber in a row.it should be created dynamically based on user requirement.I should validate each field separately to find empty field.

code:

if (_name == null || _name == '' || _name == undefined) {
                $("#lblNameError" + i).html('Please enter the  Name');
                isError = true;
            }
            //phone
            if (_phone== null || _phone== '' || _phone== undefined) {
                $("#lblphoneError" + i).html('Please entered the phone');
                isError = true;
            }
user649802
  • 3,243
  • 3
  • 20
  • 14

1 Answers1

0

I got the regular expression answer from THIS question!

Consider The Following JavaScript:

function isValid(someStringValue) {
    var regEx = /([a-zA-Z0-9_])/g;

    if(someStringValue.match(regEx).join(''))
       return true;
    else
       return false;
}

If no match is found...the value is invalid.

Also...you will get more co-operation from folks if you start marking the correct answers to your questions as "ACCEPTED". Getting answers accepted is the entire reason people are answering questions on this site.

Community
  • 1
  • 1
Prisoner ZERO
  • 13,848
  • 21
  • 92
  • 137