Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Using Pattern for Javascript in Acrobat 9 Pro

Last post 03-10-2010, 8:03 AM by mkhennafi. 2 replies.
Sort Posts: Previous Next
  •  03-09-2010, 1:55 PM 60597

    Using Pattern for Javascript in Acrobat 9 Pro

    We have experienced issues with a field value because it does not match the recommended 'pattern'. The user needs to enter her/his id on a form and it needs to match a built-in logic.  My question has to do with the control at the field level to ensure that the value entered match at list one of 3 'patterns'

    - Pattern 1 = must be 6 characters --> the first five characters must be numbers and the last one must be a number (example 12345A)

    - Pattern 2 = must be 6 characters --> the first 2 characters must be 0 and N (for instance 0N1234)

    - Pattern 3 = must be 6 characters --> First character is the letter C, characters 2 to 5 are numbers and last character is a letter (for instance C1234A)

    - Pattern 4 = must be 6 characters --> All numbers

    My questions to all the gurus are:

    If possible: How could I put all these requirement into one (can you share the script with me)? and more generally, where to look for instructions on how to set up a character string to match a pattern?

    Thanks a bunch for your (more than welcomed) help

  •  03-09-2010, 6:39 PM 60605 in reply to 60597

    Re: Using Pattern for Javascript in Acrobat 9 Pro

    Patterns #1 and #4 (ignoring your comment that there are "...3 'pattern'. ") are almost the same and can be handled by

    \d{5}[A-Z\d]

    (possibly with the "ignore case" option set if you can allow lower case letters) Also I assume that the last character in Pattern #1 should be a letter (as per your example and not as per your statement). This matches 5 digits and then a letter or a digit.

    Pattern #2 is

    0N\d{4}

    Pattern #3 can be expressed as:

    C\d{4}[A-Z]

    (again with the "ignore case" option set if necessary)

    To put these together you use the alternation operator. Also to force the pattern to match the entire input (so you don't match the 6 digits in "AB123456E") you use anchors at each end to give

    ^(\d{5}[A-Z\d]|0N\d{4}|C\d{4}[A-Z])$

    In this case the order of the alternates does not really matter. The alternates are tested in the order they are written in the pattern and so a value that matches pattern #2 will first be tried against the 'd{5}' part of the first alternate. It will match the '0' but fail on the 'N' and so move on to the 2nd alternate where it will match.

    I have not tested these pattern but they should give you a good starting point.

    As for learning how to do this, I suggest that you Google "regex tutorial" and start reading. As each regex variant has its own characteristics, you may want to add in "javascript" to the search string.

    Susan

  •  03-10-2010, 8:03 AM 60650 in reply to 60605

    Re: Using Pattern for Javascript in Acrobat 9 Pro

    Thanks very much for putting the energy and time and... oooops sorry for 3 patterns instead of 4... Will test soon and come back to you!
View as RSS news feed in XML