Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

SSN Validation Help

Avatar

Former Community Member
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

Avatar

Former Community Member
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