Solved

PDF Form validation of RegExp

Posted on 2011-02-17
9
1,306 Views
Last Modified: 2013-12-13
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

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");
}

Open in new window

0
Comment
Question by:Maplehurst
  • 5
  • 4
9 Comments
 
LVL 7

Expert Comment

by:dxdinh
ID: 34922003
can you try this

^[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

0
 
LVL 7

Expert Comment

by:dxdinh
ID: 34922025

I mean by replacing your myRegExp variable to

var myRegExp =/^[aA]0[0-9][0-9][0-9][0-9]/;
0
 
LVL 1

Author Comment

by:Maplehurst
ID: 34922099
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.
0
 
LVL 7

Expert Comment

by:dxdinh
ID: 34922588
if you do

 app.alert(wipCode );

before the Reg test

did you get the same input that you entered?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 1

Author Comment

by:Maplehurst
ID: 34924998
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!
0
 
LVL 1

Author Comment

by:Maplehurst
ID: 34926236
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
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"});
}

Open in new window

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.
0
 
LVL 7

Expert Comment

by:dxdinh
ID: 34927888
awesome - I am glad that you get it to work !!!!
0
 
LVL 7

Accepted Solution

by:
dxdinh earned 500 total points
ID: 34935250
perhaps some points to close the question - if you don't mind - unless you still have other questions
0
 
LVL 1

Author Closing Comment

by:Maplehurst
ID: 34942067
Not the complete solution but did direct me in the right direction to solving the problem
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual xHarbour 1 90
Acrobat DC hangs while converting Word docs to Adobe .PDF files within Win Explorer 7 114
pdf convertor 7 66
Christmas family picture with greetings 19 84
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now