移动电话验证-Php
很抱歉,我提出了一个对你们中的一些人来说可能相当直率的问题,但我想知道你们中是否有人可以在验证方面透露一些信息 我有一个文本字段,我需要验证一个手机号码,所以我需要验证它在开始时有+44,包括+44,它是13位长,我发现了一些不同的技术,但没有什么一步一步定义它,只是复制和粘贴,我想学习如何做,以便我知道以后的参考 任何帮助都将不胜感激移动电话验证-Php,php,html,validation,Php,Html,Validation,很抱歉,我提出了一个对你们中的一些人来说可能相当直率的问题,但我想知道你们中是否有人可以在验证方面透露一些信息 我有一个文本字段,我需要验证一个手机号码,所以我需要验证它在开始时有+44,包括+44,它是13位长,我发现了一些不同的技术,但没有什么一步一步定义它,只是复制和粘贴,我想学习如何做,以便我知道以后的参考 任何帮助都将不胜感激 谢谢虽然这可以用简单的方法来完成,但我还是希望你能借此机会学习。一旦准备好,就可以使用来应用该正则表达式 注意:根据OP的要求,为了教人钓鱼,故意对这个答案进行
谢谢虽然这可以用简单的方法来完成,但我还是希望你能借此机会学习。一旦准备好,就可以使用来应用该正则表达式
注意:根据OP的要求,为了教人钓鱼,故意对这个答案进行概括。我鼓励您在查看这些资源后,再发布一个单独的、更具体的问题。虽然这可以通过简单的方式完成,但我希望您能借此机会学习。一旦准备好,就可以使用来应用该正则表达式 注意:根据OP的要求,为了教人钓鱼,故意对这个答案进行概括。我建议在查看这些资源后,再发布一个单独的、更具体的问题。简易方法: php代码:
if (isset($_POST['send'])) {
$mobile = $_POST['mobilenumber'];
// get the first 3 string
$begin = substr($mobile,0,3);
// get the rest of the posted string and add it to 0 to make it to number
// 'intval($variable)' and '(int) $variable' do the same
$theOthers = 0+substr($mobile,3);
// OR $theOthers = intval(substr($mobile,3));
// OR $theOthers = (int) substr($mobile,3);
$ok = true;
echo strlen($mobile);
// check the first 3 string
// if it's not equal with "+44", the entry is wrong
if ($begin != "+44") {
$ok = false;
} else {
// check the length of the input
// if it's not equal with 13, the entry is wrong
if (strlen($mobile)!=13) {
$ok = false;
}
}
if ($ok) {
// do something
}
}
html代码:
<form method="post">
<input type="text" name="mobilenumber" maxlength="13" value="+44">
<input type="submit" name="send" value="Send">
</form>
简易方法:
php代码:
if (isset($_POST['send'])) {
$mobile = $_POST['mobilenumber'];
// get the first 3 string
$begin = substr($mobile,0,3);
// get the rest of the posted string and add it to 0 to make it to number
// 'intval($variable)' and '(int) $variable' do the same
$theOthers = 0+substr($mobile,3);
// OR $theOthers = intval(substr($mobile,3));
// OR $theOthers = (int) substr($mobile,3);
$ok = true;
echo strlen($mobile);
// check the first 3 string
// if it's not equal with "+44", the entry is wrong
if ($begin != "+44") {
$ok = false;
} else {
// check the length of the input
// if it's not equal with 13, the entry is wrong
if (strlen($mobile)!=13) {
$ok = false;
}
}
if ($ok) {
// do something
}
}
html代码:
<form method="post">
<input type="text" name="mobilenumber" maxlength="13" value="+44">
<input type="submit" name="send" value="Send">
</form>
0+“字符串”
?为什么不使用(int)
cast或intval()
?当然可以。结果是一样的。我有时会使用它。0+'string'
?为什么不使用(int)
cast或intval()
?当然可以。结果是一样的。我有时用这个。