c++ - QRegularExpression For Phone Number -


i trying use regular expressions validate phone numbers allowing numbers accepted not 10, regular expression ^[0-9]{10} should allow 10 numbers 0-9. test strings 1234567890 passed , 703482062323 passed. can fix issue?

the code im using test regular expression

qregularexpression phone_num("^[0-9]{10}"); // 10 numbers in phone number qregularexpressionmatch match = phone_num.match("12345612312312312121237890"); qdebug() << match.hasmatch(); 

assuming want exactly 10:

^[0-9]{10}$

match end-of-line doesn't match subset of line more 10.

#include <qregularexpression> #include <qdebug>  int main() {     qregularexpression re("^[0-9]{10}$");     qdebug() << re.match("12345678901123").hasmatch();     qdebug() << re.match("1234567890").hasmatch();     qdebug() << re.match("12345678").hasmatch();     qdebug() << re.match("123123123a").hasmatch(); } 

output:

false true false false 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -