-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip/Freeze code from asaskevich/govalidator and drop dependency #518
Strip/Freeze code from asaskevich/govalidator and drop dependency #518
Conversation
Signed-off-by: Davanum Srinivas <[email protected]>
/approve |
/assign @liggitt for pkg/validation/OWNERS approval |
/approve |
+1 to isolate would it make sense to put under https://github.com/kubernetes/kube-openapi/tree/master/pkg/internal/third_party to keep visibility limited and third party things gathered in one spot? |
Signed-off-by: Davanum Srinivas <[email protected]>
@liggitt right! we should do that! (Done!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
left breadcrumbs to the commit and location of anything non-trivial from the original repo
|
||
// Basic regular expressions for validating strings | ||
const ( | ||
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})$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Basic regular expressions for validating strings | ||
const ( | ||
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})$" | ||
ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ( | ||
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})$" | ||
ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$" | ||
ISBN13 string = "^(?:[0-9]{13})$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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})$" | ||
ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$" | ||
ISBN13 string = "^(?:[0-9]{13})$" | ||
Hexcolor string = "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$" | ||
ISBN13 string = "^(?:[0-9]{13})$" | ||
Hexcolor string = "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" | ||
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*\\)$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hexcolor string = "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" | ||
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*\\)$" | ||
Base64 string = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$" | ||
SSN string = `^\d{3}[- ]?\d{2}[- ]?\d{4}$` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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*\\)$" | ||
Base64 string = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$" | ||
SSN string = `^\d{3}[- ]?\d{2}[- ]?\d{4}$` | ||
Int string = "^(?:[-+]?(?:0|[1-9][0-9]*))$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
// IsCreditCard check if the string is a credit card. | ||
func IsCreditCard(str string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// IsISBN check if the string is an ISBN (version 10 or 13). | ||
// If version value is not equal to 10 or 13, it will be check both variants. | ||
func IsISBN(str string, version int) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
// ToInt convert the input string or any int type to an integer type 64, or 0 if the input is not an integer. | ||
func ToInt(value interface{}) (res int64, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dims, Jefftree, liggitt, sttts The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Please see #512 for context.
Notes:
github.com/asaskevich/govalidator