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
Post a Comment