0

I am trying to create a textbox in infoth form with following creteria: 1.) Length should be 7-15 characters 2.) It should contain at least one digit 3.) It should contain at least one character 4.) It should contain only digits and alphabets

[a-zA-Z1-9 ]{7,15} give seven to 15 characters alphanumeric but does not confirm that at one digit and alphabet.

I tried to add some like ^\d*[a-zA-Z][a-zA-Z0-9]*$ but no luck.

Than i trid to add "[a-zA-Z1-9 ]{7,15}" and "/d" in or condition but still not working.

Could someone please help me with this.

2 Answers 2

1

Due to the limited support for RegEx in InfoPath you'll not be able to do the verification in a single RegEx but you can do it by adding this validation rule:

FieldName | does not math pattern | [a-zA-Z\d]{7,15} | or
FieldName | does not math pattern | .*\d.*           | or
FieldName | does not math pattern | .*[a-zA-Z].*     | 

If InfoPath had had full support for RegEx including lookaheads then the regex could have been ^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z\d]{7,15}$, but even then the above is probably a little easier for many to understand

3
  • Thanks! it worked like charm. Is it possible that this field could be left blank. I mean either it could be left blank or it should match the pattern.
    – Mohit
    Commented Feb 28, 2014 at 6:09
  • If your field has "Cannot be blank" unchecked then the field can either be blank or it has to validate. (The advanced regex doesn't allow blank but could easily be modified to do that) Commented Feb 28, 2014 at 7:03
  • Perfect. you saved my buts :)
    – Mohit
    Commented Feb 28, 2014 at 7:28
0

I always struggle with regex its the language of freaks! I tend to use an online testbed, I've found debuggex to be excellent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.