Home > Article > Web Front-end > A simple example of using javascript to determine a phone number
This article mainly introduces the relevant information of javascriptJudge the phone number example written simply. Friends in need can refer to
Judge the phone number simply written in javascript
When registering on many websites, we are required to fill in the phone number. I originally wanted to fool it, but it didn't work. It kept prompting that it was incorrect. I searched a lot online, regular expression, I found a lot of mistakes,
Finally I wrote a simple but more practical one
First is the content of the html part
手机号:<input type="text" class="loginuser" placeholder="请输入您的手机号" id="uid" onblur="checkPhone()" /> <span id="uidt" style="margin-left: 100px"></span>
The content in the span tag It is mainly used to write prompts. For example, if you enter it incorrectly, you will be prompted "Please enter the correct mobile phone number." If you enter it correctly, you will be prompted "OK";
Then comes the javascript part
function checkPhone(){ var phone = document.getElementById('uid').value; if(!(/^1[34578]\d{9}$/.test(phone))){ return document.getElementById('uidt').innerHTML = '请输入正确的手机号'; return false; } else{return document.getElementById('uidt').innerHTML = 'ok';} }
Such a simple mobile phone number verification is completed
The above is the detailed content of A simple example of using javascript to determine a phone number. For more information, please follow other related articles on the PHP Chinese website!