| 1 |
package govalidator |
| 2 |
|
| 3 |
import "regexp" |
| 4 |
|
| 5 |
// Basic regular expressions for validating strings |
| 6 |
const ( |
| 7 |
CreditCard string = "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$" |
| 8 |
ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$" |
| 9 |
ISBN13 string = "^(?:[0-9]{13})$" |
| 10 |
Hexcolor string = "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" |
| 11 |
RGBcolor string = "^rgb\\(\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*\\)$" |
| 12 |
Base64 string = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$" |
| 13 |
SSN string = `^\d{3}[- ]?\d{2}[- ]?\d{4}$` |
| 14 |
Int string = "^(?:[-+]?(?:0|[1-9][0-9]*))$" |
| 15 |
) |
| 16 |
|
| 17 |
var ( |
| 18 |
rxCreditCard = regexp.MustCompile(CreditCard) |
| 19 |
rxInt = regexp.MustCompile(Int) |
| 20 |
rxISBN10 = regexp.MustCompile(ISBN10) |
| 21 |
rxISBN13 = regexp.MustCompile(ISBN13) |
| 22 |
rxHexcolor = regexp.MustCompile(Hexcolor) |
| 23 |
rxRGBcolor = regexp.MustCompile(RGBcolor) |
| 24 |
rxBase64 = regexp.MustCompile(Base64) |
| 25 |
rxSSN = regexp.MustCompile(SSN) |
| 26 |
) |