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:
must start with 5 digits (Any combination, no specific pattern)
followed by a single space
then have any combination of text and spaces I.E. CAR or CAR IS or CAR IS SUPER FAST or CARISSUPER FAST. Just looking for text, single space, text etc. However, it shouldn't allow for the text to end on anything other than a letter (no period or extra space or special character)
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.
^\d{5}\s[A-Z\s]*[A-Z]$
^
= beginning of string\d{5}
= 5 digits\s
= single space[A-Z\s]*
= any sequence of letters and spaces, possibly empty[A-Z]
= a single letter, so it can't end with a space$
= end of string