sonu33 -3 Newbie Poster

I have a text box which accepts time(max of 5 characters only), and a drop down which accepts am or pm value.

I need to perform some validations for the string values entered into the text box such as:

1) If user enters 9 => Should be changed to 0900

2) 9:3 => 0930

3) 09:3 => 0930

4) 93 => 0930

5) 115 => 0115

6) Invalid entries such as !@#$%^&*()<>?/~`,;'"[]_-abcdefg.. => alert ('Invalid Time Value') should be displayed.

So far, all I've achieved is replacing the : with ''.
For example, if user enters 09:00 => 0900

These validations need to be done within script tag. (The backend language that I've used is jsp.)

Pls help me :(

Here is a part of the code that I have written:

<script type='text/javascript'>
    function clocks(){
    
    var clk = document.getElementById('TIME').value;
    var clks = clk.replace('/:/g','');
    var ampm = document.getElementById('AMPM').value;
    var add = 1200;
    
    if (clks=="")
    {
    alert("You must enter clock time");
    }
    else
    {
    if (ampm=='p')
    {
    clks=parseFloat(clks) + parseFloat(add);
    }
    }
    
    }
    ....
    </script>
peter_budo commented: Learn the difference between Java and JavaScript. Post moved -3