Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Validate SSN


Level 4


I've been looking around a bit to find a solution to by problem, but can't seem it find it.  I want to set a script to validate an SSN entry.  If the user exits the field and they have entered it incorrectly, I want it to error and then set the focus back to that field.

I set my patterns as

Edit Pattern:  text{999-99-9999}|text{999999999}

Display and Validation Patterns: text{999-99-9999}

and I attempted to set the script as follows:


(this.rawValue =! text{999-99-9999}||text{999999999})


app.alert("Please enter SSN as 999-99-9999 or 999999999");



Can someone direct me to a post or help with my script.


6 Replies


Level 10

Here is a sample file for you..


Let me know if this helps..




Level 4

I'm not able to open your sample without updating my flashplayer and unfortunately our IT doesn't want us to upgrade yet.


Level 10

Send a test email to LiveCycle9@gmail.com (OR) send a personal message in the forum, so I can send the file to your email..




Former Community Member

Can you also send me information on how to do this?


Level 4

Hi, This is what I used.

1) Create a Script Object with the name "globalFunctions".

2) Place the below script in the script object..

function isValidSSN(SSNstr){

var ssnChar = "-";

var strMessage ="";

var pos1=SSNstr.indexOf(ssnChar);

var pos2=SSNstr.indexOf(ssnChar,pos1+1);

var strFirst=SSNstr.substring(0,pos1);

var strSecond=SSNstr.substring(pos1+1,pos2);

var strThird=SSNstr.substring(pos2+1);

//xfa.host.messageBox("First = " + strFirst + " Second = " + strSecond

+ " Third = " + strThird);

if(strFirst.length !=3 || strSecond.length != 2 || strThird.length !=


return "Not valid SSN";



return "Valid SSN";


3. Place 2 text Fields on your form.

4. In the properties of one Text Field, place the below pattens.

Display: text{999-99-9999}|text

Edit: text{999-99-9999}

In the Change event of the field, place the below script.

if (xfa.event.change.match(/[0-9\-]/) == null)

xfa.event.change = "";

In the Exit event of the field, place the below script.

var strReturnMessage = globalFunctions.isValidSSN(this.formattedValue);

if(strReturnMessage != "Valid SSN"){

xfa.host.messageBox("Please enter SSN as 999-99-9999 or 999999999");




Former Community Member

Thank you so much.

If I may, got a question on how to do 2 things.

1st. Can I create a button in the PDF that when I click on it, will open

Internet Browser and go to URL I specify?

2nd. Same as above, but can I have it do a form post to the URL I specify

and post certain values only instead of the whole form? Then, display the

results on the Internet Browser. The PDF remains open in the background.

If you can point me in the right direction, I would really appreciate it.