javascriptregexaemlivecycle-designer

Assistance with REG EXP to match 5 digit number followed by undefined amount of text i.e 99999 AAA AAA etc


I am trying to create a simple regexp in JS and no matter how many times I try I can't seem to get it to work.

Using JS in AEM Designer

I am looking for the regexp to compare a user entry that:

So far I have the 5 digits thing figured out and then a space, but I cannot seem to get the text to work the way I want.

Here is the code I am currently using in the form:

var pattern = new RegExp("^([0-9]{5}).([A-Z]+)$");
var result = Page1.Section1.MOSID.rawValue

if (pattern.test(result)) {
    xfa.host.setFocus(NextField);
} else {
    xfa.host.messageBox("Incorrect formatting, please follow format shown in caption");
}

This has gotten me part of the way there, but it only allows for 1 continuous line of text and doesn't allow spaces in between, nor does it account for the line ending.

I've been trying unsuccessfully with the following

("^([0-9]{5}).[A-Z]([.A-Z]*)$")
("^([0-9]{5}).([A-Z])([.A-Z]*)?$")
("^([0-9]{5})\s([A-Z])(\s\w+)*$")
("^([0-9]{5})\s([A-Z])+( \w+)*$")

I feel like I'm dancing around the solution but can't quite seem to get in step.

Any help would be appreciated.


Solution

  • ^\d{5}\s[A-Z\s]*[A-Z]$
    

    DEMO