This article introduces, in PHP programming, using regular expressions to determine whether a string is a domain name method, the need for friends to refer to it. Usually match the format requirements of the domain name: 1, the name of the domain names are composed of English letters and numbers, each marking no more than 63 characters, and does not distinguish between uppercase and lowercase letters. Other punctuation marks cannot be used except hyphens (-) in the label. 2, all levels of domain names with a real point (.) connection, the length of the three-level domain name can not exceed 20 characters. 3. The complete domain name consisting of multiple labels is not more than 255 characters in total.Match the regular name of the domain: 1, by the English numerals and "_" Composition [-a-z0-9]2, each level to "." Connection 3, level Three cannot have a domain length not exceeding 20 {1,20}To see an example,
The following regular expressions, all from the network, for everyone to learn the reference. Regular 1\b ([a-z0-9]+ (-[a-z0-9]+) *\.) +[a-z]{2,}\b Error Match: Length >60 regular 2^ ([^-][a-z0-9a-z-_]+\.) *) [^-][a-z0-9a-z-_]+ (\.[ a-za-z]{2,4}) {1,2}$ error match: Length >60 error match: www.te_st.com regular 3 ([\w\d\-_]+\.):? [ ^-_]) +\w{2,4} mismatch: test.com.cn error matching: www.te_st.com regular 4[a-za-z0-9][-a-za-z0-9]{0,62} (. [ A-ZA-Z0-9][-A-ZA-Z0-9]{0,62}) +.? No error regular 5 (? <=\.) ([A-za-z0-9] ([a-za-z0-9-]{0,61}[a-za-z0-9])?.) +[a-za-z]{2,6} cannot match two-level domain name regular 6 ([A-z0-9][a-z0-9\-]*?\. (?: Com|cn|net|org|gov|info|la|cc|co) (?: \. (?: CN|JP))?) $ some top-level domains do not match, use caution. |