1

i want to check for certain regex expression to make sure some string is followed by '::' and some number. The number can be between 1 and 999999999999.

for example: 'ACME LOCK & KEY::42443' should pass where 'ABC Inc.' should fail.

any help?

2 Answers 2

4

Try this:

/::[1-9]\d{0,11}$/.test(str)

This will return true for every string that ends with :: followed by an integer between 1 and 999999999999 inclusive.

Sign up to request clarification or add additional context in comments.

3 Comments

will try. will this work too? $(this).val().match(/(.*[::][0123456789])/g). UPDATE: Gumbo, that works. thanks
it's returning the string and the number of digits.
Just a note, that this doesn't currently ensure a string exists prior to the ::, so ::123 will pass.
2

Here, this will match a string that ends in :: followed by 1-12 digits.

/^.+::[1-9]\d{0,11}$/.test(stringToTest)

This also checks to make sure there is a string of at least 1 character prior to the ::

Tests:

FAIL: asdf
PASS: asdf::123
FAIL: asdf::
FAIL: asdf::0
PASS: asdf::999999999999
FAIL: asdf::9999999999999
FAIL: ::asdf
FAIL: ::999

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.