我想查看有效的联系电话: -
space
和连字符( - )。有效联系电话的示例是+ 91-8341239834或+91 033 2664 3271
该数字不得超过20个字符。
我该怎么做?
这是我的代码,直到现在: -
preg_match('/^[0-9 .\-]+$/i', $number)
答案 0 :(得分:1)
如果preg支持开始和结束锚标记,或者可能#include <iostream>
using namespace std;
int main()
{
double input;
cout << "Time Calculator\n Enter the number of Seconds: " << endl;
cin >> input;
if (input >= 86400)
{
cout << "The time is " << input << " days." << endl;
}
else if (input >= 3600)
{
cout << "The time is " << input << " hours." << endl;
}
else if (input >= 60)
{
cout << "The time is " << input << " minutes." << endl;
}
else
{
cout << "The time is " << input << " seconds." << endl;
}
return 0;
}
,则可能需要尝试/^\+?(?:[0-9 ]{1,20}|([-])(?!\1))+$/
或/(\+?[0-9 ]|([-])(?!\2))*$/
。这个带有/\+?(?:[0-9 ]{7,20}|([-])(?!\1))+/
和^
的正则表达式似乎满足了您最初提出的所有要求。
$
#matse + 9 2344235 23244
#matse + 9-2344235-23244
#matse +923212312412424
#matse 1231 231 23123213
#no match 9--232314
#no match