Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    4
    Member #
    31609
    Hi all,

    I am trying to figure out javascript for mobile / home validation.
    Just to let you know, it must be equal to 11 digits (already done it) and accept only NUMERICAL characters, so letters are not accepted once validated or when you input data.

    My issue: I don't know how to add rule to validate or do not accept letters from A-Z and other staff than numbers.

    This is my current code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    <script type='text/javascript'>
    function lengthRestriction(elem, min, max){
            var uInput = elem.value;
            if(uInput.length >= min && uInput.length <= max){
                    return true;
            }else{
                    alert("Please enter " +max+ " characters");
                    elem.focus();
                    return false;
    
            }
    }
    </script>
    
    </head>
    
    <body>
    <form>
    Username(11 characters): <input type='text' id='restrict' maxlength="11"/>
    <input type='button'
            onclick="lengthRestriction(document.getElementById('restrict'), 11, 11)"
            value='Check Field' />
    </form>
    </body>
    </html>
    I have also found ready code for numbers validation but I don't know how to merge these two codes, so it is validating for 11 digits, and at the same time accept only numbers.

    Code:
    <script type='text/javascript'>
    function isNumeric(elem, helperMsg){
            var numericExpression = /^[0-9]+$/;
            if(elem.value.match(numericExpression)){
                    return true;
            }else{
                    alert(helperMsg);
                    elem.focus();
                    return false;
            }
    }
    </script>
    <form>
    Numbers Only: <input type='text' id='numbers'/>
    <input type='button'
            onclick="isNumeric(document.getElementById('numbers'), 'Numbers Only Please')"
            value='Check Field' />
    </form>
    Anyone have any idea how to do that? :-)

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    139 times
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Junior Member
    Join Date
    May 2012
    Posts
    4
    Member #
    31609
    Thanks for your reply, as I am very weak with java, can you please modify my code or give me some examples? I need it as soon as possible to finish.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:13 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com