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 4 of 4

Thread: input mask

  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,458
    Thanks
    15
    Thanked 0 Times in 0 Posts

    input mask

    cna someone tell me how to do an input mask on a feild

    it's a text box and as someone enters the date I want it to add the /
    so it's formatted as mm/dd/yyyy (meaning after they enter in 2 numbers it adds the /

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,030
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    This is going to give problems. What if the date is 1st January or whatever? Users may not put in a leading zero.

    I suggest much better to have separate input boxes for mm dd and yyyy, and concatenate and/or format the result afterwards.

    Or try:-

    if( !/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(obj.value) ) {
    alert( "Invalid date supplied - must be format MM/DD/YYYY" );
    obj.focus();
    return;
    }

    You will still need to test if the values of mm dd and yyyy are valid.

    Just found the following which is close to what you want:-

    http://javascript.internet.com/forms/format-date.html

    Hope this helps.
    Last edited by Philip M; 05-28-2006 at 05:30 PM.

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sddsfsdfsd

    fsdfsdfsdf

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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