How to validate special characters in a textbox without using Validate plugin on JQuery
views:
1184answers:
2
+1
A:
Try this javascript
function checkSpecialKeys(e) {
if (e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 40)
return false;
else
return true;
}
Implement it on the onkeydown or onkeyup attribute of the textbox.
You can add or remove the keys you which to validate by specifying the key code.
Raúl Roa
2009-08-26 12:38:32
+4
A:
If you want to delete special characters and allow only words, spaces and numbers:
$(document).ready(function(){
$("input").keyup(function(){
var text=$(this).val();
$(this).val(text.replace(/[^\w\d\s]/,""));
})
})
mck89
2009-08-26 12:42:50
+1 I'm a year late but very helpful answer, thanks
kekekela
2010-08-10 20:36:32