In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The purpose of this article is to share with you the content of how to check the rules of English numbers and other related characters without using regularities in php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Rule checking of related characters such as English numbers without using regularities
In some scenarios, such as when registering and logging in, we impose some restrictions on the user name, such as a combination of numbers and letters. Normally, we use regular expressions to do this, but PHP has actually prepared us to send several functions to handle such situations.
Ctype_ related functions / / numbers and letters, excluding floating-point numbers, [A-Za-z0-9]
If (ctype_alnum ($input)) {
Echo $input,'is a combination of English numbers!' , PHP_EOL
}
/ / English letter, [A-Za-z]
If (ctype_alpha ($input)) {
Echo $input,'it's the English alphabet!' , PHP_EOL
}
/ / numeric characters, excluding floating point numbers, negative numbers (unsigned positive integers)
If (ctype_digit ($input)) {
Echo $input, 'numeric characters!' , PHP_EOL
}
The above three functions are divided into numbers + letters, pure letters, pure numbers of the three character types of judgment. Yes, we use these functions at the beginning of ctype_ for this judgment. Among them, the only thing to note is that when ctype_digit () makes a number judgment, the return of true can only be a positive integer with no sign and no decimal point, that is to say, negative numbers and decimals can not be judged by this function. We'll also look at the difference between ctype_digit () and is_numeric () at the end of the article.
Of course, there are not only three ctype_-related functions, but many more. Let's take a look at another set.
/ / lowercase letters
If (ctype_lower ($input)) {
Echo $input, 'lowercase characters!' , PHP_EOL
}
/ / Capital letters
If (ctype_upper ($input)) {
Echo $input,'is an uppercase character!' , PHP_EOL
}
/ / all printable characters
If (ctype_print ($input)) {
Echo $input,'is a printable character!' , PHP_EOL
}
/ / all characters are visible except for spaces or format controls that are not visible
If (ctype_graph ($input)) {
Echo $input,'is a printable character, except white space characters!' , PHP_EOL
}
/ / English punctuation marks of printable characters that do not contain blanks, letters or numbers
If (ctype_punct ($input)) {
Echo $input,'is a printable character that does not contain white space, letters, or numbers!' , PHP_EOL
}
Ctype_lower () and ctype_upper () determine whether the contents of the string are all lowercase or uppercase. Remember, the condition is that everything in the string must be uppercase or lowercase, and if there is a letter that is not, then true cannot be returned. Of course, these two judgments must also be in the English alphabet, there must be no numbers, spaces and so on.
Ctype_print () determines whether it is printable content. What is printable content? It's what echo, print and the like can output and you can see on the screen.
Ctype_graph () is a printable character except for white space characters. What is a white space character? Tabulation symbols such as\ n and\ t, as well as our normal spaces are white space characters.
Ctype_punct () can be simply understood as punctuation marks. The whole string is made up of punctuation marks and does not contain blank content.
/ /\ n\ t\ r and so on
If (ctype_cntrl ($input)) {
Echo $input,'is a format control character!' , PHP_EOL
}
/ / Spac
If (ctype_space ($input)) {
Echo $input,'is a space character!' , PHP_EOL
}
/ / hexadecimal AB10BC99
If (ctype_xdigit ($input)) {
Echo $input,'is a hexadecimal character!' , PHP_EOL
}
Appearance tabs are not very popular, don't be afraid, ctype_cntrl () is to determine whether the whole character is made up of these tabs.
Ctype_space () can tell from the name whether it is a string made up of spaces.
Ctype_xdigit () is our last ctype_ function, and you can tell from the name that it determines whether it is a hexadecimal string.
The difference between ctype_digit () and is_numeric ()
Both functions determine whether the argument is numeric, but one big difference between them is that ctype_digit () is only for strings. That is to say, it is used to determine whether the content in a string is numeric. If you give it a normal numeric type directly, it will return false, and it will think that the content of this numeric type is not a "string" type of number.
/ / the difference between ctype_digit and is_numeric
$numeric_string = '42'
$integer = 42
Echo ctype_digit ($numeric_string), PHP_EOL; / / true
Echo ctype_digit ($integer), PHP_EOL; / / false (ASCII 42 is the * character)
Echo is_numeric ($numeric_string), PHP_EOL; / / true
Echo is_numeric ($integer), PHP_EOL; / / true
Thank you for reading! This is the end of the article on "how to check the rules of English numbers and other related characters without regular use in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.