SitePoint Sponsor

# Thread: RegExp Double Digit Question

1. ## RegExp Double Digit Question

I am trying to restrict the input of number through RegExp but dont understand how to limit the double digit maximum input.

In Field one Max Number allow is 8 which is working fine but how can i restrict Max 16 number in Field 2?

Code:
```<script language="javascript">
function Nonly(fld, pat){
if(!pat.test(fld.value))
{
fld.value = '';
return false;
}
}
</script>```
HTML Code:
```<input name="A-20" id="A-20" value="" onkeyup="return Nonly(this, /^[0-8]*\$/);" type="text" size="2" maxlength="1" /> Maximum Allow 8
<input name="A-22" id="A-22" value="" onkeyup="return Nonly(this, /^([0-9]|[0-6])*\$/);" type="text" size="2" maxlength="2" /> Maximum Allow 16```

2. In Field one Max Number allow is 8 which is working fine
What does this say:
Code:
```var str = "66666";
var re = /^[0-8]*\$/;
alert( re.test(str) );```

but how can i restrict Max 16 number in Field 2?
Code:
```function Nonly(fld, limit)
{
var val = parseInt(fld.value);
if( isNaN(val) || val > limit)
fld.value = "";
}
onkeyup="return Nonly(this, 8)"
onkeyup="return Nonly(this, 16)"```

3. Thanks Man for prompt response.

4. /^([0-9]|[0-6])*\$/
You're almost there
Code:
`/^([0-9]|1[0-6])\$/`

#### Posting Permissions

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