MVC Textbox Allow Only alphabets andNumbers in text box using java script
Step1:index.cshtml
@Html.TextBoxFor(m => m.AddressLine1, new { @class = "txtprofilephy", placeholder = "AddressLine1", @onkeypress = "return numChar(event);", @maxlength = 35 })
Step2: javascript
<script>
function numChar(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 8 || charCode == 32 || (charCode >= 48 && charCode <= 57))
return true;
return false;
}
</script>
Step1:index.cshtml
@Html.TextBoxFor(m => m.AddressLine1, new { @class = "txtprofilephy", placeholder = "AddressLine1", @onkeypress = "return numChar(event);", @maxlength = 35 })
Step2: javascript
<script>
function numChar(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 8 || charCode == 32 || (charCode >= 48 && charCode <= 57))
return true;
return false;
}
</script>
No comments:
Post a Comment