-
-
Notifications
You must be signed in to change notification settings - Fork 940
Validate #72
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
Validate #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,11 @@ | |
| bth[buf[i++]] + bth[buf[i++]]; | ||
| } | ||
|
|
||
| // **`validate(str)` - Test whether given string a valid UUID** | ||
| function validate(str) { | ||
| return /[0-9a-f]{22}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i.test(str); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey zeke, I know you pulled his from #41, where I offered this as a one-liner solution, but if we're going to add a regex-based validate() method, it should conform as closely as possible to what RFC4122 does/doesn't allow. Specifically:
Thus, this regex: (edited: to add ^ & $ to regex) |
||
| } | ||
|
|
||
| // **`v1()` - Generate time-based UUID** | ||
| // | ||
| // Inspired by https://github.com/LiosK/UUID.js | ||
|
|
@@ -222,6 +227,7 @@ | |
| uuid.v4 = v4; | ||
| uuid.parse = parse; | ||
| uuid.unparse = unparse; | ||
| uuid.validate = validate; | ||
| uuid.BufferClass = BufferClass; | ||
|
|
||
| if (typeof define === 'function' && define.amd) { | ||
|
|
||
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.
These tests for more rigor: