JQuery Validator Plugin Phone Validation

前端 未结 3 1659
情歌与酒
情歌与酒 2021-02-10 07:09

I\'m having issues with the jquery validator validating phone numbers. So in a form where I have an input for phone number, I use jquery\'s additional methods to validate the ph

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-10 07:50

    You are using the phoneUS validation method for the phone number, which accepts both of the inputs below (examples):

    • 949-101-2020
    • 9491012020

    Since the first example is considered valid, you attempt to store it directly into your database, and it seems that you are using an integer or number column. Many databases, including MySQL will attempt to coerce that value into an integer by simply dropping everything after the first non-numeric character. I always recommend using a varchar field for storing phone numbers because the numbers don't really have a numeric meaning (ie you're never going to add/subtract).

    Also, it's a bad idea to simply rely on client side validation. You always want to validate your data on the server side because it's very trivial to trick client side validation (maliciously or not).

提交回复
热议问题