SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb problem in telephone validation

    // tel

    var y;
    y=document.getElementById('tel').value
    if((y.length==0) || (y.charAt(0)==' '))
    {
    alert(telno);
    document.getElementById(3).style.color="#FF0100"; // b
    document.getElementById('tel').focus();
    return false;
    break;
    }
    var p
    p=document.getElementById('tel').value;
    if((p.length!=0))
    {
    b=parseInt(document.getElementById('tel').value);
    if(isNaN(b))
    {
    alert(numonly);
    document.getElementById(3).style.color="#FF0100";
    document.getElementById('tel').value="";
    document.getElementById('tel').focus();
    return false;
    break;
    }
    else
    document.getElementById(3).style.color="#000000";
    }

    for telephone if i enter dfsdhf it display an error msg (numonly)

    but if i enter "33223sdsdds"

    it works correctly and dont detect the letters inside numbers
    now i want to for the telephone to detect each character if it is a num or letter and if it found letter then display error msg wherever is this letter.




    thnx in advance

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    var telNumber = '038928372';
    if(telNumber.match(/^[\+]?([0-9\s-])+$/)) {
        alert('VALID');
    } else {
        alert('INVALID');
    }
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


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
  •