Hello everyone, I am going to share the special characters
validation using JavaScript/jQuery.
Example as given below
$(function () {
$("form
:input[type='text']").on("keyup", function (e) {
var inputTextId = $('#' + this.id);
var inputText = inputTextId.val();
var errorFor = this.id;
if (!isValidChar(inputText)) {
$('#' + this.id).val('').valid();
setTimeout(function () { replaceErrorMsg(errorFor);
}, 100);
}
});
});
function isValidChar(str) {
return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
}
function replaceErrorMsg(errorFor) {
$("label[for='" + errorFor + "'].help-block").html("Input
parameter is Invalid.");
}
For more detail, go to links