0

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.

Fatin Az
  • 509
  • 2
  • 6
  • 8

3 Answers3

0

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 = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
UdayKiran Pulipati
  • 6,579
  • 7
  • 67
  • 92
0

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;
    }
});
Community
  • 1
  • 1
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
0

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);" />
ravisolanki07
  • 637
  • 3
  • 13