validation pattern for text field (number only) | Community
Skip to main content
Nov 5, 2007 11:05 PM UTC

validation pattern for text field (number only)

Hi, Im trying to create a field that users can only enter number. If they enter text, an error message should pop up. I can't seem to get it to work although i got the error message to show when users enter text. However, im not sure what i need to put in the "validation pattern" box. Should it be 9 or 99999 or 999999999. None of those worked, as i have tried. If someone has any idea. Please help. Thanks.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

13 replies

Mar 5, 2008 11:03 AM UTC
How to Disable Print option in Pdf. i am using Adobe Designer Live Cycle. plz Reply
Translate
Mar 5, 2008 11:00 AM UTC
How to Disable Print option from Toolbar in Pdf. plz reply.
Translate
Nov 12, 2007 4:24 PM UTC
That works... Thanks much Geo and Chris.

:-)
Translate
Level 8
Nov 9, 2007 10:21 PM UTC
Download "LiveCycle Designer Scripting Basics", http://www.adobe.com/devnet/livecycle/articles/lc_designer_scripting_basics/lc_designer_scripting_basics.pdf , and read section 8 Creating and Reusing JavaScript Functions. For the provided code you will be creating a script object titled "docLevel" at the form level.
Translate
Nov 9, 2007 7:53 PM UTC
Geo,

I added the defining for "onlyNum" and "onlyNumMsg" but it's still not showing the error message. You and Chris keep saying "adding as the doc level" What does that mean? Did i not put the script in the right place?

Thanks.
Translate
Level 8
Nov 9, 2007 6:51 PM UTC
You have to define the "onlyNum" RegExp and the "onlyNumMsg" variables and the "validateField" function as a document level script:



var onlyNum = /^\d*$/;

var onlyNumMsg = "Please enter only numeric values.";



function validateField (getField, getRegex, getAlertMsg)

{

var fieldFocus = xfa.resolveNode(getField);

var regex = new RegExp();

regex.compile(getRegex);

var runRegex = regex.test(fieldFocus.rawValue);



if (fieldFocus.rawValue != null && runRegex == false)

{

app.alert(getAlertMsg, 1, 0, "Your Caption");

fieldFocus.rawValue = null;

xfa.host.setFocus(getField);

}

}



And use the following function call for the "validation" action for the field in question:



docLevel.validateField (this.name, docLevel.onlyNum, docLevel.onlyNumMsg);
Translate
Nov 9, 2007 6:21 PM UTC
Hi Chris,

This is what i have in the events with Scripts:

----- form1.#subform[0].TextField1::exit - (JavaScript, client) ------------------------------------



docLevel.validateField (this.name, docLevel.onlyNum, docLevel.onlyNumMsg);



----- form1.#subform[0].TextField1::validate - (JavaScript, client) --------------------------------



function validateField (getField, getRegex, getAlertMsg)

{

var fieldFocus = xfa.resolveNode(getField);

var regex = new RegExp();

regex.compile(getRegex);

var runRegex = regex.test(fieldFocus.rawValue);



if (fieldFocus.rawValue != null && runRegex == false)

{

app.alert(getAlertMsg, 1, 0, "please enter only number");

fieldFocus.rawValue = null;

xfa.host.setFocus(getField);

}

}

I also took everything out in the Object>Value>Validation Pattern.

Now, when i enter text or number, the field takes both and throws no error message. I still want the error message if user enters text instead of number. I think im still missing something. Do you have a sample that you could send me? Thanks.

Jaclyn
Translate
Nov 8, 2007 7:48 AM UTC
Hi Jaclyn,



Remove everything from the validation Pattern box & uncheck the error box.



You just need to use the function "function validateField" as a doc level and "docLevel.validateField (this.name, docLevel.onlyNum, docLevel.onlyNumMsg); " you place in the exit event of the text field.



Regards,



Chris Fourie

www.intelliform.co.za
Translate
Nov 7, 2007 7:36 PM UTC
Hi Chris,

I put the script that you gave me in the validate & exit events of the text field. Under Object>Value of the text field, do i still need to put in 99999 for the validation Pattern box? and do i need to check the error box as well?

Right now, i got the error message "TextField1 validate failed. Did i not put the code in the right placE?

Please advise.

Thanks
Translate
Nov 7, 2007 9:58 AM UTC
Hi Jaclyn,



Sorry I gave you the Acrobat scripts and not Designer.



here are the Designer scripts:



function validateField (getField, getRegex, getAlertMsg)

{

var fieldFocus = xfa.resolveNode(getField);

var regex = new RegExp();

regex.compile(getRegex);

var runRegex = regex.test(fieldFocus.rawValue);



if (fieldFocus.rawValue != null && runRegex == false)

{

app.alert(getAlertMsg, 1, 0, "Your Caption");

fieldFocus.rawValue = null;

xfa.host.setFocus(getField);

}

}



Put this in the exit event of the text field:



docLevel.validateField (this.name, docLevel.onlyNum, docLevel.onlyNumMsg);



Regards,



Chris Fourie

www.inteliform.co.za
Translate