简体   繁体   中英

How can I check a valid user's phone number in JavaScript?

I am creating an input form on a web page. That's on field in phone number get in user.now How can I check now if the user's phone number is a wallet? my user lives in bangladesh.

you can use regex to check mobile phone:

 ^\+?(88)?0?1[3456789][0-9]{8}\b

If you are trying to implement real world project phone validation then there are two ways I know that can be used:-

After basic regex check on the phone number, you can.....

(i) setup an OTP based system so that user has to fill OTP on your page that was sent to his phone number to validate the number.

(ii) use a phone number validator api if you just want to check if the number is correct or not and belongs to a particular country. There are many free web api's present that you can use in your project.

You can use this function for that:

function validatePhone(phone){
    let p = ^\+?(88)?0?1[3456789][0-9]{8}\b;
    return p.test(phone);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM