checking textbox field

Discussion in 'HTML & Website Design' started by rrn, May 26, 2009.

  1. #1
    in my website ther is a textbox for entering year..

    i have given code for displaying an alert message if the textbox is left empty..


    
       1. function validate() {
       2. if(document.form.year.value=="")
       3. {
       4. alert ('Please enter year');
       5. return false;
       6. }}
    
    PHP:



    it is working , but i want to do is..

    it should display an alert message if the length of the numbers is less than 4 or greater than 4

    how can i do that??

    please give me a solution...
    thanks......
     
    rrn, May 26, 2009 IP
  2. Straightupimp

    Straightupimp Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your asking for it to display a separate alert message is the length is greater or less than 4?
     
    Straightupimp, May 26, 2009 IP
  3. rrn

    rrn Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes..
    i want to display a seperate alert message if the length is greater or less than 4..
     
    rrn, May 26, 2009 IP
  4. Richjd

    Richjd Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi, this function should solve it for you.

    Cheers,
    Rich..

    function validate()
    {
    if(document.form.year.value=="")
    {
    alert ('Please enter year');
    return false;
    }

    else if(document.form.year.value.length > 4)
    {
    alert ('The year must be in the format "YYYY"');
    return false;
    }

    else if(document.form.year.value.length < 4)
    {
    alert ('The year must be in the format "YYYY"');
    return false;
    }

    }
     
    Richjd, May 26, 2009 IP