Answer the question
In order to leave comments, you need to log in
Translate regular expression in PHP?
Hello. There are functions for checking e-mail and phone number for validity.
function ValidMail(n) {
var re = /^[\w-\.][email protected][\w-]+\.[a-z]{2,4}$/i;
var valid = re.test(n);
return valid;
}
function ValidPhone(n) {
var re = /^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/i;
var valid = re.test(n);
return valid;
}
Answer the question
In order to leave comments, you need to log in
The syntax is the same
$foo = '[email protected]';
preg_match('/^[\w-\.][email protected][\w-]+\.[a-z]{2,4}$/i', $foo, $matches);
echo $matches[0];
Regular expressions themselves are universal for programming languages. But the syntax of their declaration and record is somewhat different. In JS, you can enter, for example, as a string with escaping, or a RegExp constructor . In PHP I don't remember there being any difference (in terms of escaping), but you should refer directly to the documentation for that.
At the same time, as SagePtr correctly noted in the comments, the service configurator allows you to check both the regular expression and get its form in the PL. Pay attention to the panel on the left.
here is a good material on regular expressions php old.code.mu/books/php/regular/rabota-s-regularnym...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question