I saw some questions here but no one works for me. This regex should only accept phone numbers. I need to use expressions as strings because I need to get them from a data- attribute.
This is the code:
$('.valid_mobile').change(function(event) {
var rex = '^0\d{10}$';
var message = 'This is not a valid mobile phone number.';
var text = $(this).val();
var regex = new RegExp(rex);
if (! regex.test(text))
{
alert(message);
$(this).val('');
}
console.log(regex.test(text));
console.log($(this).val());
});