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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -