├── LICENSE ├── README.md └── images ├── char1.png ├── char10.png ├── char11.png ├── char2.png ├── char3.png ├── char4.png ├── char5.png ├── char6.png ├── char7.png ├── char8.png ├── char9.png ├── chineses.png ├── domain-name.png ├── email.png ├── email2.png ├── ip.png ├── num1.png ├── num10.png ├── num2.png ├── num3.png ├── num4.png ├── num5.png ├── num6.png ├── num7.png ├── num8.png ├── num9.png ├── phone.png ├── phone2.png ├── regex.png └── userid.png /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 ZiHang Gao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | 4 | 5 | 6 |
7 | 8 | ## 目录 9 | 10 | - [邮箱](#邮箱) 11 | - [电话](#电话) 12 | - [域名](#域名) 13 | - [IP](#ip) 14 | - [帐号校验](#帐号校验) 15 | - [字符校验](#字符校验) 16 | - [汉字](#汉字) 17 | - [英文和数字](#英文和数字) 18 | - [长度为3-20的所有字符](#长度为3-20的所有字符) 19 | - [英文字符](#由英文字符) 20 | - [由26个英文字母组成的字符串](#由26个英文字母组成的字符串) 21 | - [由26个大写英文字母组成的字符串](#由26个大写英文字母组成的字符串) 22 | - [由26个小写英文字母组成的字符串](#由26个小写英文字母组成的字符串) 23 | - [由数字和26个英文字母组成的字符串](#由数字和26个英文字母组成的字符串) 24 | - [由数字、26个英文字母或者下划线组成的字符串](#由数字26个英文字母或者下划线组成的字符串) 25 | - [中文、英文、数字包括下划线](#中文英文数字包括下划线) 26 | - [中文、英文、数字但不包括下划线等符号](#中文英文数字但不包括下划线等符号) 27 | - [禁止输入含有^%&',;=?$\"等字符](#禁止输入含有等字符) 28 | - [禁止输入含有~的字符](#禁止输入含有的字符) 29 | - [数字正则](#数字正则) 30 | - [整数](#整数) 31 | - [正整数](#正整数) 32 | - [负整数](#负整数) 33 | - [非负整数](#非负整数) 34 | - [非正整数](#非正整数) 35 | - [浮点数](#浮点数) 36 | - [正浮点数](#正浮点数) 37 | - [负浮点数](#负浮点数) 38 | - [非负浮点数](#非负浮点数) 39 | - [非正浮点数](#非正浮点数) 40 | 41 | ## 邮箱 42 | 43 | `gaozihang-001@gmail.com` 只允许英文字母、数字、下划线、英文句号、以及中划线组成 44 | 45 | ```regex 46 | ^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$ 47 | ``` 48 | 49 | ![email](images/email.png) 50 | 51 | `高子航001Abc@bowbee.com.cn` 名称允许汉字、字母、数字,域名只允许英文域名 52 | 53 | ```regex 54 | ^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$ 55 | ``` 56 | 57 | ![email](images/email2.png) 58 | 59 | ## 电话 60 | 61 | `13012345678` 手机号 62 | 63 | ```regex 64 | ^1(3|4|5|6|7|8|9)\d{9}$ 65 | ``` 66 | 67 | ![phone](images/phone.png) 68 | 69 | `XXX-XXXXXXX` `XXXX-XXXXXXXX` 固定电话 70 | 71 | ```regex 72 | (\(\d{3,4}\)|\d{3,4}-|\s)?\d{8} 73 | ``` 74 | 75 | ![email](images/phone2.png) 76 | 77 | ## 域名 78 | 79 | `https://google.com/` 80 | 81 | ```regex 82 | ^((http:\/\/)|(https:\/\/))?([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}(\/) 83 | ``` 84 | 85 | ![domain-name](images/domain-name.png) 86 | 87 | ## IP 88 | 89 | `127.0.0.1` 90 | 91 | ```regex 92 | ((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d)) 93 | ``` 94 | 95 | ![ip](images/ip.png) 96 | 97 | ## 帐号校验 98 | 99 | `gaozihang_001` 字母开头,允许5-16字节,允许字母数字下划线 100 | 101 | ```regex 102 | ^[a-zA-Z][a-zA-Z0-9_]{4,15}$ 103 | ``` 104 | 105 | ![user](images/userid.png) 106 | 107 | ## 字符校验 108 | 109 | ### 汉字 110 | 111 | `高子航` 112 | 113 | ```regex 114 | ^[\u4e00-\u9fa5]{0,}$ 115 | ``` 116 | 117 | ![chinese](images/chineses.png) 118 | 119 | ### 英文和数字 120 | 121 | ```regex 122 | ^[A-Za-z0-9]+$ 123 | ``` 124 | 125 | ![char](images/char1.png) 126 | 127 | ### 长度为3-20的所有字符 128 | 129 | ```regex 130 | ^.{3,20}$ 131 | ``` 132 | 133 | ![char](images/char2.png) 134 | 135 | ### 英文字符 136 | 137 | #### 由26个英文字母组成的字符串 138 | 139 | ```regex 140 | ^[A-Za-z]+$ 141 | ``` 142 | 143 | ![char](images/char3.png) 144 | 145 | #### 由26个大写英文字母组成的字符串 146 | 147 | ```regex 148 | ^[A-Z]+$ 149 | ``` 150 | 151 | ![char](images/char4.png) 152 | 153 | #### 由26个小写英文字母组成的字符串 154 | 155 | ```regex 156 | ^[a-z]+$ 157 | ``` 158 | 159 | ![char](images/char5.png) 160 | 161 | #### 由数字和26个英文字母组成的字符串 162 | 163 | ```regex 164 | ^[A-Za-z0-9]+$ 165 | ``` 166 | 167 | ![char](images/char6.png) 168 | 169 | #### 由数字、26个英文字母或者下划线组成的字符串 170 | 171 | ```regex 172 | ^\w+$ 173 | ``` 174 | 175 | ![char](images/char7.png) 176 | 177 | ### 中文、英文、数字包括下划线 178 | 179 | ```regex 180 | ^[\u4E00-\u9FA5A-Za-z0-9_]+$ 181 | ``` 182 | 183 | ![char](images/char8.png) 184 | 185 | ### 中文、英文、数字但不包括下划线等符号 186 | 187 | ```regex 188 | ^[\u4E00-\u9FA5A-Za-z0-9]+$ 189 | ``` 190 | 191 | ![char](images/char9.png) 192 | 193 | ### 禁止输入含有%&',;=?$\"等字符 194 | 195 | ```regex 196 | [^%&',;=?$\x22]+ 197 | ``` 198 | 199 | ![char](images/char10.png) 200 | 201 | ### 禁止输入含有~的字符 202 | 203 | ```regex 204 | [^~\x22]+ 205 | ``` 206 | 207 | ![char](images/char11.png) 208 | 209 | ## 数字正则 210 | 211 | ### 整数 212 | 213 | ```regex 214 | ^-?[1-9]\d*$ 215 | ``` 216 | 217 | ![num](images/num1.png) 218 | 219 | #### 正整数 220 | 221 | ```regex 222 | ^[1-9]\d*$ 223 | ``` 224 | 225 | ![num](images/num2.png) 226 | 227 | #### 负整数 228 | 229 | ```regex 230 | ^-[1-9]\d*$ 231 | ``` 232 | 233 | ![num](images/num3.png) 234 | 235 | #### 非负整数 236 | 237 | ```regex 238 | ^[1-9]\d*|0$ 239 | ``` 240 | 241 | ![num](images/num4.png) 242 | 243 | #### 非正整数 244 | 245 | ```regex 246 | ^-[1-9]\d*|0$ 247 | ``` 248 | 249 | ![num](images/num5.png) 250 | 251 | ### 浮点数 252 | 253 | ```regex 254 | ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ 255 | ``` 256 | 257 | ![num](images/num6.png) 258 | 259 | #### 正浮点数 260 | 261 | ```regex 262 | ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ 263 | ``` 264 | 265 | ![num](images/num7.png) 266 | 267 | #### 负浮点数 268 | 269 | ```regex 270 | ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ 271 | ``` 272 | 273 | ![num](images/num8.png) 274 | 275 | #### 非负浮点数 276 | 277 | ```regex 278 | ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ 279 | ``` 280 | 281 | ![num](images/num9.png) 282 | 283 | #### 非正浮点数 284 | 285 | ```regex 286 | ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ 287 | ``` 288 | 289 | ![num](images/num10.png) 290 | 291 | ## License 292 | 293 | MIT License. See the [LICENSE](LICENSE) file. 294 | 295 | **[⬆ top](#目录)** 296 | -------------------------------------------------------------------------------- /images/char1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char1.png -------------------------------------------------------------------------------- /images/char10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char10.png -------------------------------------------------------------------------------- /images/char11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char11.png -------------------------------------------------------------------------------- /images/char2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char2.png -------------------------------------------------------------------------------- /images/char3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char3.png -------------------------------------------------------------------------------- /images/char4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char4.png -------------------------------------------------------------------------------- /images/char5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char5.png -------------------------------------------------------------------------------- /images/char6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char6.png -------------------------------------------------------------------------------- /images/char7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char7.png -------------------------------------------------------------------------------- /images/char8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char8.png -------------------------------------------------------------------------------- /images/char9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/char9.png -------------------------------------------------------------------------------- /images/chineses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/chineses.png -------------------------------------------------------------------------------- /images/domain-name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/domain-name.png -------------------------------------------------------------------------------- /images/email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/email.png -------------------------------------------------------------------------------- /images/email2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/email2.png -------------------------------------------------------------------------------- /images/ip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/ip.png -------------------------------------------------------------------------------- /images/num1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num1.png -------------------------------------------------------------------------------- /images/num10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num10.png -------------------------------------------------------------------------------- /images/num2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num2.png -------------------------------------------------------------------------------- /images/num3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num3.png -------------------------------------------------------------------------------- /images/num4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num4.png -------------------------------------------------------------------------------- /images/num5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num5.png -------------------------------------------------------------------------------- /images/num6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num6.png -------------------------------------------------------------------------------- /images/num7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num7.png -------------------------------------------------------------------------------- /images/num8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num8.png -------------------------------------------------------------------------------- /images/num9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/num9.png -------------------------------------------------------------------------------- /images/phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/phone.png -------------------------------------------------------------------------------- /images/phone2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/phone2.png -------------------------------------------------------------------------------- /images/regex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/regex.png -------------------------------------------------------------------------------- /images/userid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdoco/common-regex/b3460fc2b38cd1d34dc038ac39d72980aea64c62/images/userid.png --------------------------------------------------------------------------------