views:

34

answers:

2

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?

+4  A: 

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.

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

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
Chad