SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Karachi, Pakistan
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #3
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Karachi, Pakistan
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Man for prompt response.

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    /^([0-9]|[0-6])*$/
    You're almost there
    Code:
    /^([0-9]|1[0-6])$/


Bookmarks

Posting Permissions

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