0

useing this code I avoid to paste invalid chracters to textboxes.

function PasteAlphaNumeric(objEvent)
{
var strPasteData = window.clipboardData.getData("Text");
var objInput = objEvent.srcElement;
if (strPasteData.search("[^A-Za-z0-9]")!=-1) {
alert("The character you attempted to paste is not allowed for this field.");
objInput.focus();
return false;
}
}

I want to allow to paste white space characters (\s) and[A-Za-z0-9] to the textbox, how can I do this.

2
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by aish
0

You could use an expression modifier, to add the /s to your character array. I haven't tested it, and it's late, but try:

function PasteAlphaNumeric(objEvent)
{
  var strPasteData = window.clipboardData.getData("Text");
  var objInput = objEvent.srcElement;
  if (strPasteData.search("[^A-Za-z0-9][B]+/s[/B]")!=-1)
  {
    alert("The character you attempted to paste is not allowed for this field.");
    objInput.focus();
    return false;
  }
}
0

thanks for your advice, but it was not working, any other ideas?

0

Sorry. Include the "\s" special character within your character class. You'll need to escape the blackslash WITH a backslash. For example this works:

function testRegEx(x)
{

  var regex = new RegExp("[^A-Za-z0-9\\s]");

  if (x.value.search(regex) != -1)
  {
    alert("Invalid Entry.");
  }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.