January 7th, 2013, 05:56 PM
In need of some reg exp assistance, I would like to remove all characters from a user's input except for those I designate. I have it working all except if a space is added which I would like to keep. I have included the code I am using below. As you can see, I would like to keep all alphanumerics as well as ?, *, and -. I have tried added \s inside and outside the brackets and the spaces remain; however the end user can use special characters (%, #, &, etc) which I want to disallow.
document.getElementById("trackingID").value = acctNum.replace(/[^\A-Za-z0-9?*-]/g, "");
Maybe I am going about this the wrong way and should use something other than a regular expression. I am open for any suggestions
Thanks in advance.
January 8th, 2013, 10:29 AM
Just an FYI. I was able to fix the issue.
document.getElementById("trackingID").value = acctNum.replace(/[^\A-Za-z0-9?*\-\s]/g, "");
The reg exp was using the - as a range instead of a literal. I \-\s at the end and it is keeping the spaces as well as the dash.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.