Automatic Formate the US phone number while entering.

Discussion in 'JavaScript' started by strgraphics, Mar 25, 2011.

  1. #1
    Hello mates..,

    i have contact details page for my users in US,
    When entering the phone numbers we must format it as (923)-634-1234. It should automatically insert the necessary hipens and parantheisis).

    i would like to achieve this in the js any ideas please help me friends.

    Would be Great full to your help, thanks
     
    strgraphics, Mar 25, 2011 IP
  2. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Jan Novak, Mar 26, 2011 IP
  3. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Hello Jan, its working great thanks a lot....!!!!!

    But i have once more doubt.., if i click submit button then in the database it will stores only the digits or it includes the braces ?
     
    strgraphics, Mar 27, 2011 IP
  4. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #4
    It depends on server side script (PHP, ASP, JAVA etc.). Server side script receives value from a form and communicates with database and should know datatype of the column in database. This is important, because if you have e.g. bigint datatype, you cant store in it non numeric characters.

    For performance reasons, searching in database, index using, it should be fine to have int or bigint datatype. You can easily format 9236341234 into (923)-634-1234 format in PHP.

    It is not a good idea to do input verification at client side only. Do it also in server side to avoid database injection.

    If you need help, feel free to contact me via PM.
     
    Jan Novak, Mar 28, 2011 IP
  5. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Yes sure Jan....!!
    For now am good to go, really thanks for your help...!!!!!
     
    strgraphics, Mar 28, 2011 IP