Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: validate 6 numeric digits??

1. ## validate 6 numeric digits??

Hi guys!
If I have a field called "number" how can I validate that the user enters a 6 digit long number and also validate against a user typing "000000"?
Tracy

• Originally Posted by nikko50
Hi guys!
If I have a field called "number" how can I validate that the user enters a 6 digit long number and also validate against a user typing "000000"?
Tracy
Code:
`result = /^[1-9]\d{5}/.test(numbervalue);`
result is true for any number from 100000 to 999999.

regards

• What if they are allowed to type in "011225". Number that start with 0.

• Originally Posted by nikko50
What if they are allowed to type in "011225". Number that start with 0.
Code:
```val = parseInt(numval,10);
result = (val > 0 && val <= 999999) ? true : false);```
from 1 to 999999.

regards

• if (/^\d{6}\$/.test(number.value) && (number.value > 0)) {

returns true for 000001 to 999999 (I understand that the user must enter exactly 6 digits with leading zeroes as necessary)

If the six digit number must be at least 100000 then:-

if (/^\d{6}\$/.test(number.value) && (number.value >= 100000)) {

or as proposed by oesxyl

if (/^[1-9]\d{5}\$/.test(number.value)) { // \$ sign essential
returns true for 100000 - 999999

• ## Users who have thanked Philip M for this post:

oesxyl (04-21-2008)

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•