How regular expressions are applied flexibly in PHP--Regular expressions

Source: Internet
Author: User

Regular expressions, also known as pattern expressions, have a very complete set of syntax systems that can write patterns, providing a flexible and intuitive method of string processing. Regular expressions can be used to match, find, replace and split strings by constructing patterns with specific rules and comparing them with input string information.

This program is implemented with a regular expression to implement login verification of a demo

<1>:

<?php 
if (isset ($_post["sub")) { 
$text =$_post["text"]; 
$patten = ' ^[0-9]*$ '; 
if (!preg_match ($patten, $text, $x)) { 
echo "<script>alert (' user does not enter number ');</script>"; 
} else{ 
if ($x <1) { 
$y = $x; 
echo "y=". $y. " <br> "; 
} else if ($x <10) { 
$y =2* $x-1; 
echo 
"y=". $y. " <br> "; 
} else{ 
$y =3* $x -11; 
echo "y=". $y. " <br> "; 
} 
? > 
 
 

<2>:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.