Reg expression for SSN and Tax ID

Avatar

Avatar
Validate 10
Level 3
SI_MSD7
Level 3

Likes

17 likes

Total Posts

220 posts

Correct reply

10 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
SI_MSD7
Level 3

Likes

17 likes

Total Posts

220 posts

Correct reply

10 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
SI_MSD7
Level 3

16-02-2017

Hi,

I'm looking for a way to validate that a user has entered a value matching either XXX-XX-XXXX or XX-XXXXXXX format. Ideally, the field will only allow numeric and "-" characters to be entered, but if that's too difficult...I could live with it simply ensuring that either format was entered (perhaps on the Exit event).

The script below seems to work HOWEVER it allows the user to enter the Tax ID with 8 digits following the "-" instead of a max of 7 digits. So basically, it accepts XX-XXXXXXX (9 X's) AND XX-XXXXXXXX (10 X's) and it shouldn't allow the latter.

var r = new RegExp();

r.compile("[0-9]{3}\-[0-9]{2}\-[0-9]{4}");

 

var s = new RegExp();

  s.compile("[0-9]{2}\-[0-9]{7}");

var result = r.test(this.rawValue);

var result2 = s.test(this.rawValue);

if (result !== true & result2 !== true  )

{

xfa.host.messageBox("Please enter your SS # in XXX-XX-XXXX format, or a Tax ID in XX-XXXXXXX format");

}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
Magus069
MVP

16-02-2017

Hi there,

don't forget to mention to your regular expression that you want your text to end exactly with these characters...

right now, your regular expression validate if it is true that the value entered contains exactly either (XXX-XX-XXXX) OR (XX-XXXXXXX)

After this being validated it doesn't verify whether if the text ends there or not, as long as this is what it contains it's good with it...

If you want to make sure that you have a maximum length in your string you want it to be entered, don't forget the use of $

Hope this help!

Answers (1)

Answers (1)

Avatar

Avatar
Validate 10
Level 3
SI_MSD7
Level 3

Likes

17 likes

Total Posts

220 posts

Correct reply

10 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
SI_MSD7
Level 3

Likes

17 likes

Total Posts

220 posts

Correct reply

10 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
SI_MSD7
Level 3

16-02-2017

Ahhh...got it. Thank you!!!