Design a site like this with
Get started

Function to validate name for numbers and special characters


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;

                $('#UserRole').css('border-color', 'green');
                return true;



<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)" })

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at

Up ↑

%d bloggers like this: