Created
July 10, 2019 08:06
-
-
Save ppsirius/74ac410634d5dba8f7566c5e20b5aad4 to your computer and use it in GitHub Desktop.
aws s3 bucket name validation RegEx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
bucketNameValidationRules: [ | |
// rules from https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-s3-bucket-naming-requirements.html | |
v => !!v || 'Name is required', | |
v => (v && /^[\a-z\d\.\-]*$/.test(v)) || 'The bucket name can contain only lower-case characters, numbers, periods, and dashes.', | |
v => (v && /^[\a-z\d]/.test(v)) || 'The bucket name must start with a lowercase letter or number.', | |
v => (v && !/\-$/.test(v)) || `The bucket name can't end with a dash`, | |
v => (v && !/\.+\./.test(v)) || `The bucket name can't have consecutive periods`, | |
v => (v && !/\-+\.$/.test(v)) || `The bucket name can't end with dash adjacent to period`, | |
v => (v && !/^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$/.test(v)) || `The bucket name can't be formatted as an IP address`, | |
v => (v && (v.length >= 3 && v.length <= 63)) || 'The bucket name can be between 3 and 63 characters long.' | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment