My regular expression is /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/ and in html I added it as a hidden element with the value of the element set to the above pattern
When I do this:
var regex = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/
var text = $(this).val()
and then test with regex.test(text) it works fine.
but when I assign regex like this:
var regex = $("#m"+id).val() // (my hidden element)
then it doesnt work. I have tried assigning it using new RegExp as well but also not working.I think it's doing it because it's returning the value as a string from $("#m"+id).val() (I am getting the right value returned here), but not sure what to parse it to.
Any help would be appreciated.