Is there a standard for storing normalized phone numbers in a database?

前端 未结 18 1449
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 19:23

What is a good data structure for storing phone numbers in database fields? I\'m looking for something that is flexible enough to handle international numbers, and also som

18条回答
  •  抹茶落季
    2020-11-28 19:27

    Ok, so based on the info on this page, here is a start on an international phone number validator:

    function validatePhone(phoneNumber) {
        var valid = true;
        var stripped = phoneNumber.replace(/[\(\)\.\-\ \+\x]/g, '');    
    
        if(phoneNumber == ""){
            valid = false;
        }else if (isNaN(parseInt(stripped))) {
            valid = false;
        }else if (stripped.length > 40) {
            valid = false;
        }
        return valid;
    }
    

    Loosely based on a script from this page: http://www.webcheatsheet.com/javascript/form_validation.php

提交回复
热议问题