Hi there guys(and gals),
I'm working on a form to accept a telephone number that is a standard USA 7 digit number, with a separate field for the area code (Not the best method, I know) . So I set it to format as a phone number. Yet I do not want the hyphen (-) because the form is submitted to a database where the phone number is set to INT, so a hyphen will break the number. I also know that format isn't the value, but most people try to be helpful, and type the hyphen even though Acrobat interprets a phone number and automatically puts the hyphen for visual appeal. So I write a regular expression to accept only numbers in the !event.willCommit keystroke. All is good. But then I ran into the issue of not being able to backspace in the event the user makes an error.. So I figured I'd just look up the Javascript Regex value for a backspace. The exception is: [\b] So my code looked like this:
var backspacerxp = /\d[\b]/; // \d is for digits only
var test = event.change;
console.println(backspacerxp.test(test));
if(backspacerxp.test(test))
{
event.rc = true;
}
I could enter a number, and the console would show TRUE. But if I hit backspace, I'd get a FALSE. So I went some other routes. I've looked up the Binary, Octal and Hex values for the UTF code of backspace. I tried all those as well. Nothing worked. What am I doing wrong? Also, for the person that does know how to accept a backspace via Regex, does that also include the Delete key, as it is interpreted to delete the character in front of the cursor, rather than the one behind it? Or... if you can suggest a better method to go at this. The form is submitted to a PHP page, which I wouldn't have any issue scrubbing the text further, but I want to get it client-side, and use my server side technology after. The less work my server has to do, the faster the response back to the client and the lower the chance of timing out.
The documentation Acrobat provided for the AcroJS API doesn't really cover Regular Expressions in any detail (As it's not API, but rather a core function supported since ECMA 1.2), so I've resorted to other online resources. Perhaps someone here with extensive AcroJS history would know.
I look forward to any response.
like this:
The AFMergeChange and AFExactMatch functions used above are built-in functions available for you to use. If you're interested in learning how they work you'll have to study their source code.
George