validation pattern for text field (number only) | Community
Skip to main content
November 5, 2007

validation pattern for text field (number only)

  • November 5, 2007
  • 13 replies
  • 8579 views
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

March 5, 2008
How to Disable Print option in Pdf. i am using Adobe Designer Live Cycle. plz Reply
March 5, 2008
How to Disable Print option from Toolbar in Pdf. plz reply.
November 12, 2007
That works... Thanks much Geo and Chris.

:-)
New Participant
November 9, 2007
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.
November 9, 2007
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.
New Participant
November 9, 2007
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);
November 9, 2007
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
November 8, 2007
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
November 7, 2007
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
November 7, 2007
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