I have placed one text area and I want to put restriction on it ..
Only special characters | should not be allowed to input in text area because I'm using | character in split function.
I have placed one text area and I want to put restriction on it ..
Only special characters | should not be allowed to input in text area because I'm using | character in split function.
Call this javascript function at your textbox
function isSpclChar(){
var iChars = "|";
if(document.qfrm.q.value.indexOf(iChars) != -1) {
alert ("This special character is not allowed.");
return false;
}
}
if you don't want to allow special charaters in textbox
then use
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
check this link first
how do i block or restrict special characters from input fields with jquery?
you need to do the opposite here, just look to match for '|'
$('input').bind('keypress', function (event) {
var regex = new RegExp("^[a-zA-Z0-9]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
var patt=/|/g;
var result=patt.test( key ) ;
if (!result) {
event.preventDefault();
return false;
}
});
You can do like this :
Script
:
function alpha(e) {
var k = (evt.which) ? evt.which : event.keyCode
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
HTML
:
<input type="text" id="id" onkeypress="return alpha(event);" />