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

November 7, 2007
Hi Jaclyn,



You can use a Regex to validate the field. You execute the valation script in the blur event of the field.



Place these in our doc level:



var onlyNum = /^\d*$/;

var onlyNumMsg = "only numeric values allowed";



function validateField (getFieldObject, getRegex, getAlertMsg, getFieldValue)

{

var fieldValue;

if (getFieldValue != null) fieldValue = getFieldValue;

else fieldValue = getFieldObject.value;



if (fieldValue != "" && getRegex.test(fieldValue) == false)

{

app.alert(getAlertMsg, 1, 0, "Jaclyn Tran");

getFieldObject.value = "";

getFieldObject.setFocus();



}

}



Put this script in the blur event of your text field you need to validate:



validateField (event.target, onlyNum, onlyNumMsg);



Trust this helps,



Chris Fourie

www.intelliform.co.za
November 6, 2007
Chris,

That is exactly that i tried but it didn't work. 2. Create a text field. Go to Validation pattern (Object>Value). Use drop down and select 99999. Then select Validation Pattern Message error.

The error message pops up even when i enter number in the field, unless i enter exactly 5 numbers... (for 99999, i assume)... is there a work around for this so i still can enter as many numbers as i like?

Thanks.
November 6, 2007
Hi Jaclyn,



You have two options:



1. Create a numeric field (not text field)which will only except numeric values.



2. Create a text field. Go to Validation pattern (Object>Value). Use drop down and select 99999. Then select Validation Pattern Message error. Don't forget to enter your message.



Regards,



Chris