Expand my Community achievements bar.

validating number length

Avatar

Former Community Member
so i have the code to validate before printing and i need to add to one field a validation checking the number length. how do i add it to this code?



else if(ccnum.rawValue == null)

{

app.alert("Enter credit card number.");

xfa.host.setFocus("ccnum");

}



the number obviously has to be 16 digits.



thanks
1 Reply

Avatar

Level 5
Following code may help you. This code is based on patterns in JavaScript.



var v1 = trim(this.rawValue);

var ccnumPat = /^(\d{16})$/;

var matchArray = v1.match(ccnumPat); // is the format ok?

//xfa.host.messageBox(""+matchArray);

if (matchArray == null) {

app.alert("A 16 Degit CC number is required.");

xfa.host.setFocus(this.name);

}else {

this.rawValue = v1;

}



Good luck

SekharN