I have script :
<script>
jQuery(document).ready(function($) {
var firstname = "/^[A-Za-z]+$/";
var email = /^[ ]*([^@@\s]+)@@((?:[-a-z0-9]+\.)+[a-z]{2,})[ ]*$/i;
jQuery('input#firstname').bind('input propertychange', function() {
if (firstname.test(jQuery(this).val())) {
jQuery(this).css({
'background': '#C2D699'
});
} else {
jQuery(this).css({
'background': '#FFC2C2'
});
}
});
jQuery('input#email').bind('input propertychange', function() {
if (email.test(jQuery(this).val())) {
jQuery(this).css({
'background': '#C2D699'
});
} else {
jQuery(this).css({
'background': '#FFC2C2'
});
}
});
});
</script>
and in view i have two textboxes in my view:
@Html.TextBoxFor(m => m.Register.FirstName, new { id = "firstname", @class = "form-control", @maxlength = "16" })
@Html.TextBoxFor(m => m.Register.Email, new { id = "email", @class = "form-control", @type = "email" })
For email validation is working but for firstname its not..What im doing wrong?