Maplehurst
asked on
PDF Form validation of RegExp
Hi,
I'm hoping for a little help trying to validate a acrobat form.
One of the fields that has to be filled in is a specific code (the letter A followed by 0 and then any 4 digits, i.e., A03546.
I'm hoping to use RegExp in a javascript on the submission button to validate this but, well i'm not very good at javascript so far i have following but am not really going anywhere.
any help appreciated
Thanks
I'm hoping for a little help trying to validate a acrobat form.
One of the fields that has to be filled in is a specific code (the letter A followed by 0 and then any 4 digits, i.e., A03546.
I'm hoping to use RegExp in a javascript on the submission button to validate this but, well i'm not very good at javascript so far i have following but am not really going anywhere.
any help appreciated
Thanks
var wipCode = this.getField("WIP");
var myRegExp =/[aA](?=0[0-9][0-9][0-9][0-9])/i;
if (myRegExp.test(wipCode)==false)
{
app.alert("This is not a valid WIP code.");
}
else
{
this.submitForm("mailto:me@myemail.com");
}
I mean by replacing your myRegExp variable to
var myRegExp =/^[aA]0[0-9][0-9][0-9][0-
ASKER
Unfortunately not quite there, all values activate the alert box, even if they follow the desired pattern.
I suspect the issue lies more with how the javascript function handles what it see as at present it fails all results rather than applies the Expression.
I suspect the issue lies more with how the javascript function handles what it see as at present it fails all results rather than applies the Expression.
if you do
app.alert(wipCode );
before the Reg test
did you get the same input that you entered?
app.alert(wipCode );
before the Reg test
did you get the same input that you entered?
ASKER
Ah...that gives me a dialog box with [object Field] in, I guess I should have seen what Is in the form. A step forwards I think!
ASKER
Bingo all seemed rather simple in the end
All i had missed was getting the value of the "WIP Code" field.
As to whether this is perfect code or not who knows but it just the job I need
All i had missed was getting the value of the "WIP Code" field.
As to whether this is perfect code or not who knows but it just the job I need
var wipCode = this.getField("WIP code").value;
var myRegExp =/^[aA]0[0-9][0-9][0-9][0-9]/;
if (myRegExp.test(wipCode)!==true)
{
app.alert(wipCode+" is not a valid WIP code.");
}
else
{
this.submitForm({cURL:"mailto:me@myemail.com",cSubmitAs: "PDF"});
}
dxdinh, thanks for the help as the extra alert sent me in the right direction and the site will be really helpful in the future.
awesome - I am glad that you get it to work !!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Not the complete solution but did direct me in the right direction to solving the problem
^[aA]0[0-9][0-9][0-9][0-9]
I use this site to test regEx when I need to write one
http://www.regular-expressions.info/javascriptexample.html