Simple regex not working in Javascript -


my regex next

/^(\.\w*)|(\d*\.?\d*)$/ 

it should works float numbers (123.23, 12., .56) , words starts dot.
confused when
/^(\.\w*)|(\d*\.?\d*)$/.test("qweasdzxc"); // return true
without or:

/^(\.\w*)$/.test("qweasdzxc"); // return false    /^(\d*\.?\d*)$/.test("qweasdzxc"); // return false 

on regexpal works well

try this

/^((\.\w*)|(\d*\.?\d*))$/.test("qweasdzxc"); // false /^((\.\w*)|(\d*\.?\d*))$/.test(".5"); // true 

you must encapsulate regex condition (a|b).


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -