Solution
In Jquery
var ValidateName= function (usr)
{
var regexp = new RegExp('^[A-Za-z]+$');
var check = $(usr).val();
if (!regexp.test(check)) {
alert('Numbers and Special Characters are not allowed');
$('#UserRole').css('border-color', 'red');
return false;
}
else
{
$('#UserRole').css('border-color', 'green');
return true;
}
}
HTML
<div class="col-sm-4 tb-font">
@Html.Label("Role", "User Role", new { style = "width:140px; margin-bottom:5px; margin-top:5px; float: left;" })
@Html.TextBox("UserRole", null, new { @class = "form-control text-box", @onchange = "ValidateName(this)" })
</div>
Leave a comment