These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Regular Expression can't 'see' backspace' to allow or catch the pesky critter

dave K
Registered: Oct 4 2011
Posts: 17

Please,
I am trying to collect an email address in a field. I have the regualr expression for that done, but now am working within the quirks of Acrobat Forms. I have created a keystroke script, but can not find a way to allow backspace, disallow spaces and special characters from the form user.
 
Here is one of the many tries, witth the part I can not make work at the end...
 
Could someone show me how to make the [/b] function?
console.clear();
console.show();
console.println("event.willCommit:" + event.willCommit)
 
var re3 = /^[\w]$/
var re4 = /^[/b]$/ //backspace ? no work
var re5 = /^\t$/ // tab ? no work
 
if (event.willCommit == false){

if (re3.test(event.change) == false) {
event.rc = false
console.println(util.printf("did not pass re3"))
}
}
if (event.willCommit == false){
if ((event.change) == " ") {
console.println(util.printf("found SPACE "))
event.rc = false
}
}
if (event.willCommit == false){
if ((event.change) == "@") {
console.println(util.printf("found @"))
event.rc = true

}
}
if (event.willCommit == false){
if (re4.test(event.change.keycode) == true) {
console.println(util.printf("to allow backspace"))
event.rc = true

}
}

Dave K

try67
Expert
Registered: Oct 30 2008
Posts: 2398
What exactly are you trying to achieve?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

dave K
Registered: Oct 4 2011
Posts: 17
Thanks, I am trying to accept a string (later to be processed in an on-blur event). That is working nicely to exclude spurious characters (!#$, etc). When I return focus to the bogus field/value, I would like the string to be able to be edited on the fly by the document's user. I want to allow the backspace key to be pressed, just not the space, etc. There is supposedly support using the [\b] in a regular expression, but that does not seem to function in what I posted. I have tried looking for the hex 8 combination, and that did not work for me either. This is also an educational effort to help be better able to control field input... problem is that with tabbing out, popping back in, etc there are a lot of ways for a person to put in characters that I don't want to test later, and catching them this way seemd appropriate. I can allow the @ just fine. I can take . and not , etc. BUT I can't keep all and sundry special key presses out and still allow the person to back up into a string (once they have been told thre is a problem (such as a string of charcters or a typo.

Dave K

try67
Expert
Registered: Oct 30 2008
Posts: 2398
No need to re-invent the wheel. Acrobat has not one but two built-in email validation methods, albeit hidden ones. Search these forums for "email validation" and I'm sure you'll find some useful tips.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

dave K
Registered: Oct 4 2011
Posts: 17
Thanks, I will search more for the unpublished (? "Double Secret" )built in methods. :)

That said, could you or some other colleague please show me a tiny snippet of code that uses a regular expression illustrating the capture of a backspace key pres?? The /^[\b]/ did not do so nor did my experimnts with the hex 8 representation...
I look forward to a suggestion with thanks.

Dk

Dave K

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Here's another topic that covers the validation of a text field that's used to enter an email address: http://forums.adobe.com/thread/857974?tstart=0

You cannot detect the backspace key press in a keystroke event. That's really not the right approach, since more than one character can be pasted/removed at a time. In general, if using the Keystroke event to filter characters, you should look at what the entry would be if allowed and either accept or reject it. The following topic has a Keystroke script that demonstrates what I'm talking about: http://forums.adobe.com/message/3667808
dave K
Registered: Oct 4 2011
Posts: 17
Thank you for the speedy reply and of course furter things to look at; I did look at that script at http://forums.adobe.com/thread/857974?tstart=0 and appreciate the reference.

Unfortunately ref script has some of the same problems I did in the script above: If I tab to a second box, with an incomplete address, the non-email address is left behind. If I enter random characters, or use a # sign in the box, then click or tab out of the field, I still have an unvalidated entry.

Please, could you show me how to set a the numeric represntation of the backspace keypress into a variable? I see that it is hex 8 but don't know the syntax, as x00008, 0x8, etc don't seem to be acceptable to Javascript.

Thanks, Dk

Dave K

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to use it like this (as the custom validate script):
event.rc = event.value=="" || eMailValidate(event.value);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com