Reputation: 511
On my asp.net web application I am restricting the user input characters using a
JQuery function
$(document).ready(function () {
$('input').on('input', function () {
var c = this.selectionStart,
r = /[^a-z0-9@&%./() +-]/gi,
v = $(this).val();
if (r.test(v)) {
$(this).val(v.replace(r, ''));
c--;
}
this.setSelectionRange(c, c);
});
});
Functions works on textbox as expected but its not working on multiline textbox.
[design eg:<asp:TextBox ID="txtAddAdds" class="form-control" placeholder="Default Input" autocomplete="off" runat="server" TextMode="MultiLine"></asp:TextBox
]
Why this function have no effect on multiline textbox.??
Somebuddy please help me..
Upvotes: 0
Views: 179
Reputation: 12880
Your function is only targeting inputs
, you need to target textareas
too :
$(document).ready(function () {
$('input, textarea').on('input', function () {
var c = this.selectionStart,
r = /[^a-z0-9@&%./() +-]/gi,
v = $(this).val();
if (r.test(v)) {
$(this).val(v.replace(r, ''));
c--;
}
this.setSelectionRange(c, c);
});
});
Upvotes: 1