0

I Have next pattern: [a-z[A-Z]а-я[А-Я][0-9]їЇіІєЄ[-][,]_"/\ ]{0,483}

<input
 id="<?= $field['id'];?>"
 name="input"                       
 <?php if (isset($field['regex'])) echo "pattern=".$field['regex'];?>
>

By this pattern I check data in field by javascript:

var decode_pattern = $(this).attr('pattern');
var reg = RegExp("^" + decode_pattern + "$");

But when i try to input (sdfzsdf) in field, regexp tell me - wrong.

Why?

4
  • You put the validation pattern directly in the markup? This just doesn't seem right. Commented May 23, 2013 at 6:56
  • 2
    @ChristopherW — w3.org/TR/html5/forms.html#the-pattern-attribute Commented May 23, 2013 at 6:56
  • @Quentin, fancy! Check my box for learning something new today. Commented May 23, 2013 at 6:57
  • What's the result you get for reg? Commented May 23, 2013 at 6:57

1 Answer 1

1

I Have this pattern: [a-z[A-Z]а-я[А-Я][0-9]їЇіІєЄ[-][,]_"/\ ]{0,483}

JavaScript Regex syntax does't allow character classes in character classes. Maybe you meant

[a-zA-Zа-яА-Я0-9їЇіІєЄ,_"/\\ -]{0,483}

Your current regex is equivalent to /[a-z\[A-Z]а-я[А-Я]\dїЇіІєЄ-,_"\/ \]{0,483}/.

Also, since it contains a quote you will need to html-escape your attribute value:

echo 'pattern="'.htmlspecialchars($field['regex']).'"';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.