Thursday 28 December 2017

javascript - Is this the right code to achieve form validation using jquery?

I am trying to validate an input text field using the
following code but when i type in any letter it throws the else yet i want it to allow
any letter but does not begin with a
digit



             class="input-group">




$(document).ready(function(){
$( "#c_name"
).keyup(function() {

var data= /^[A-Za-z]+$/;
if
($("#c_name").val() == data) {
$(this).addClass("cash");

$(this).removeClass("cashs");
}else{

$(this).addClass("cashs");
$(this).removeClass("cash");

}

});

}); ```

I expect it
to add a class cash if it begins with a
letter.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...