javascript - how to check entered regex pattern and example are correct or not -


i have 2 textbox in form. first regex pattern, , second input text.

i try check enter regex pattern , entered text matches or not.

this my simple attempt.

and working demo:

'01-01-2012'.match( /\d{2}-\d{2}-\d{4}/ ) 

fiddle

any solution query?

use var pattern = new regexp($('#pattern').val());. in case have enter pattern without slashes, \d{2}-\d{2}-\d{4} (or can make check presence , cut them).

though can create regexp in code var pattern = /\d{2}-\d{2}-\d{4}/, when pattern input field , assign variable, javascript not parse regular expression, assign string variable. , because of have explicitly create regexp object , pass string constructor, interpreter create regular expression it.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -