MVC Textbox Allow Only alphabets and Dot(.) in text box using java script
Step1: Javascript Code
<script>
function Char(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 46 || charCode == 8)
return true;
return false;
}
</script>
Step2: index.cshtml
<p>@Html.TextBoxFor(m => m.Name, new { @class = "txtreg", @id = "Name", @placeholder = "Name", @onkeypress = "return Char(event);" })</p>
Step1: Javascript Code
<script>
function Char(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 46 || charCode == 8)
return true;
return false;
}
</script>
Step2: index.cshtml
<p>@Html.TextBoxFor(m => m.Name, new { @class = "txtreg", @id = "Name", @placeholder = "Name", @onkeypress = "return Char(event);" })</p>
No comments:
Post a Comment