I am trying to build regex to allow only the following type of string: 9 digits followed by 2 letters followed by 4digits.
I came up with ^([0-9]{9})([A-Z]{2})([0-9]{4})$
but DocuSign doesn’t like it and an error message pops up: Save Error Some fields might be out of sync. The regular expression provided is not valid.
other types I have tried and failed:
^(\d{9}\d([A-Z]{2})\d{4})$ - also failed
^([0-9]{9})((\s)([a-zA-Z]{2})((\s)([0-9]{4})?$ (so this would mean there would be spaces in between numbers and letters
I think maybe something is not correct around letter validation?
Best answer by JohnSantos
@AgaB -
Your regular expression is almost correct, but there's a small mistake in it. Instead of using (\s) to match spaces between digits and letters, you should use \s* to match zero or more spaces. Also, you can simplify it a bit. Here's the corrected version:
regex
Copy code
^([0-9]{9})\s*([A-Za-z]{2})\s*([0-9]{4})$
In this expression:
^ asserts the start of the string.
([0-9]{9}) matches exactly 9 digits.
\s* matches zero or more spaces.
([A-Za-z]{2}) matches exactly 2 letters, either uppercase or lowercase.
\s* matches zero or more spaces.
([0-9]{4}) matches exactly 4 digits.
$ asserts the end of the string.
This should match the pattern you described: 9 digits followed by 2 letters followed by 4 digits, with optional spaces in between.
Your regular expression is almost correct, but there's a small mistake in it. Instead of using (\s) to match spaces between digits and letters, you should use \s* to match zero or more spaces. Also, you can simplify it a bit. Here's the corrected version:
regex
Copy code
^([0-9]{9})\s*([A-Za-z]{2})\s*([0-9]{4})$
In this expression:
^ asserts the start of the string.
([0-9]{9}) matches exactly 9 digits.
\s* matches zero or more spaces.
([A-Za-z]{2}) matches exactly 2 letters, either uppercase or lowercase.
\s* matches zero or more spaces.
([0-9]{4}) matches exactly 4 digits.
$ asserts the end of the string.
This should match the pattern you described: 9 digits followed by 2 letters followed by 4 digits, with optional spaces in between.
You can login or register as either a Docusign customer or developer. If you don’t already have a Docusign customer or developer account, you can create one for free when registering.
You can login or register as either a Docusign customer or developer. If you don’t already have a Docusign customer or developer account, you can create one for free when registering.