Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts

    check predetermine format.

    Hi, i had some predetermine format of data need to check my javascript.

    this the code i write:
    Code:
    reg = /\d{2}\:\d{2} H/;
    
    if(!reg.test(hours1))
        alert("wrong format."):
    the format i want is "00:00 H" a space at left hand side of the value H.

    but it can get what i want.

    can anyone correct for me?

    thanks

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,797
    Thanks
    19
    Thanked 156 Times in 147 Posts
    Code:
    <script type="text/javascript">
    
    reg = /\d{2}:\d{2} H/;
    
    var hours1 = '34:86 H';
    var hours2 = '4:86 H';
    var hours3 = '34:6 H';
    var hours4 = '34:86H';
    var hours5 = '34:86';
    
    if (!reg.test(hours1))
        alert('"'+hours1+'" is the wrong format.');
    else
        alert('"'+hours1+'" is the correct format.');
    
    if (!reg.test(hours2))
        alert('"'+hours2+'" is the wrong format.');
    else
        alert('"'+hours2+'" is the correct format.');
    
    if (!reg.test(hours3))
        alert('"'+hours3+'" is the wrong format.');
    else
        alert('"'+hours3+'" is the correct format.');
    
    if (!reg.test(hours4))
        alert('"'+hours4+'" is the wrong format.');
    else
        alert('"'+hours4+'" is the correct format.');
    
    if (!reg.test(hours5))
        alert('"'+hours5+'" is the wrong format.');
    else
        alert('"'+hours5+'" is the correct format.');
    
    </script>
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

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