Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SSN Validation Help

Ryan_Lunka
Level 5
Level 5
I am creating a form that is to validate if the user has entered a valid SSN. I selected the correct validation pattern and checked "Error" to show the error message, but I would like to immediately reset the focus to the SSN field if it is invalid. I understand logically how to do this but I can't figure out the actual script for it.

_________________________



Taxpayer.#subform[0].Section1.TaxpayerSSN.fldTaxpayerSSN1::validate - (JavaScript, client)



if (!!!HERE IS WHAT I CANT FIGURE OUT!!!)

{

xfa.host.setFocus(this)

}



_________________________



Any help?
1 Reply
Ryan_Lunka
Level 5
Level 5
Well, nevermind. I guess I figured out a solution. Just for reference, here is what I came up with. Most notable is the fact that I moved to the "Exit" event.



Taxpayer.#subform[0].Section1.TaxpayerSSN.fldTaxpayerSSN1::exit - (JavaScript, client)



var re = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(\d{2})\2(\d{4})$/;

if (!re.test(this.rawValue) && this.rawValue != null)

{

xfa.host.messageBox("Please enter a valid Social Security Number");

xfa.host.setFocus(this);

}

else

{

var temp = value;

if (value.indexOf("-") != -1)

{

temp = (value.split("-")).join("");

}

if (value.indexOf(" ") != -1)

{

temp = (value.split(" ")).join("");

}

if (temp.substring(0, 3) == "000")

{

xfa.host.messageBox("Please enter a valid Social Security Number");

xfa.host.setFocus(this);

}

if (temp.substring(3, 5) == "00")

{

xfa.host.messageBox("Please enter a valid Social Security Number");

xfa.host.setFocus(this);

}

if (temp.substring(5, 9) == "0000")

{

xfa.host.messageBox("Please enter a valid Social Security Number");

xfa.host.setFocus(this);

}

}



I borrowed and modified this code from this location:

http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256F6A0072B54C