我有一个登录表单,它使用电话号码而不是默认电子邮件来验证用户。
通常情况下,这样可以正常工作,但是因为我为了方便用户而在输入字段中格式化了数字,所以它是以白色空格发送的。
实施例
我从表格寄出的号码:18 23 23 54
数据库中的内容:18232354
因此我需要删除空格。
我拥有什么(LoginController.php):
public function username() {
return "number";
}
我想要的(LoginController.php):
public function username() {
return (int)str_replace(" ","",$number);
}
显然上述情况是不可能的,只是为了显示预期的结果。
任何帮助将不胜感激!
答案 0 :(得分:0)
这将返回没有空格的6em
:
#wizard {
background-color: #eee;
display:inline-block;
padding:15px;
}
#wizard .step {
display: inline-block;
width: 40px;
height: 40px;
background-color: transparent;
border: 1px solid #000;
border-radius: 50%;
text-align: center;
padding: 2px;
margin-right: 3em;
margin-left: 3em;
position: relative;
}
#wizard .step::after {
content: '';
display: block;
position: absolute;
top: 50%;
left: 46px;
width: 6em;
height: 1px;
background-color: #000;
}
#wizard .step:last-child::after {
display:none;
}
#wizard .step span {
padding: 11px;
display: block;
}
答案 1 :(得分:0)
剥离所有非数字字符更安全。例如,如果将来您希望使用-
格式化数字,例如18-23-23-54
。所以你的代码可能是:
preg_replace("/[^0-9]+/g", "", $number);