I want to restrict the use of comma in textbox. Initially the textbox is disabled and only when the user clicks on a related checkbox, the textbox is enabled.
Here is the code I have tried:
function checkForComma(keyCode) {
if (event.keyCode == 188) {
alert('Not allowed');
}
}
And the EditorTemplate:
@Html.TextBoxFor(m => m.AddressLine1, @Model.isUsed ?
(object)new { @class = "form-control" } :
new { @class = "form-control", @disabled = "disabled", @onkeypress = "checkForComma(this);" })
@Html.ValidationMessageFor(m => m.AddressLine1)
you forgot to place return
false
in your function. modify you function followingAlso modify your html code as following