Skip to content
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

Add isValid methods #85

Closed
NatWeiss opened this issue May 16, 2014 · 11 comments
Closed

Add isValid methods #85

NatWeiss opened this issue May 16, 2014 · 11 comments

Comments

@NatWeiss
Copy link

Hi Broofa, nice project here. ;) Just a suggestion. It would be nice if there was a method sort of like:

nodeUuid.isV4(someUuidString);

That way it would be easy to know if a string is a valid UUID v4. Right now, I have to resort to something janky like this:

if (!uuid || uuid.length < 32 || uuid.indexOf("-") < 0) {
    uuid = nodeUuid.v4();
}
@marbemac
Copy link

marbemac commented Mar 9, 2015

For those wondering how to validate a UUID v4, the regex looks like this (in JS, but generally applicable):

var id = "the id to test";
/^[a-z0-9]{8}-[a-z0-9]{4}-4[a-z0-9]{3}-[a-z0-9]{4}-[a-z0-9]{12}$/.test(id)

@tracker1
Copy link

tracker1 commented Mar 9, 2015

@NatWeiss @tjconcept might want to take a look at validator, which will give you a lot more than just UUID validation.

@tjconcept
Copy link

@tracker1 "a lot more" is a bad thing in my book ;-)
Thanks @marbemac, I still think it would be a nice addition to this library though.

@marbemac
Copy link

@tjconcept I agree, would be a nice addition to the library.

@tracker1
Copy link

@tjconcept @marbemac Although I understand the concern... I'm assuming you have to validate more than just UUIDs in your application... that being the case a common abstract for validation is probably better than a custom one for each type of data.

@lianghua1987
Copy link

Yeah, I like this idea!

@tjconcept
Copy link

I'm assuming you have to validate more than just UUIDs in your application...

No I don't :)

@vdininski
Copy link

+1

@jtemplet
Copy link

I also think this would be a great idea and I also like the syntax suggested above:

nodeUuid.isValid(input)
// returns boolean

I'd volunteer to add this feature

@jiayihu
Copy link

jiayihu commented Feb 16, 2016

+1
Is this repo still active? I'd like also to add this feature but the pending Pull Requests are not reassuring.

@mindvox
Copy link

mindvox commented Oct 29, 2016

This is an old issue, but would be a great feature 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants