javascript - Vue.js component html input pattern validation not working - Stack Overflow

So I'm attempting to make html forms that use the input html attribute 'pattern' however

So I'm attempting to make html forms that use the input html attribute 'pattern' however when I do so through Vue.js ponents, its creating very strange behavior. Here is a fiddle to demonstrate.

Vueponent('test', {
template:`<input type="text" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}"
title="Must contain at least one number and one uppercase and lowercase letter, and be between 8 and 16 characters."/>`
})

jsfiddle Demo

Breakdown of the patterns regex here (regex101 example).

Now for the life of me, I cannot figure out why the normal version validates properly, but the Vue version does not.

So I'm attempting to make html forms that use the input html attribute 'pattern' however when I do so through Vue.js ponents, its creating very strange behavior. Here is a fiddle to demonstrate.

Vue.ponent('test', {
template:`<input type="text" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}"
title="Must contain at least one number and one uppercase and lowercase letter, and be between 8 and 16 characters."/>`
})

jsfiddle Demo

Breakdown of the patterns regex here (regex101 example).

Now for the life of me, I cannot figure out why the normal version validates properly, but the Vue version does not.

Share asked Sep 27, 2017 at 14:02 Hex CrownHex Crown 7631 gold badge10 silver badges24 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

Your Vue input is missing a backslash on the \d pattern. The single \ gets interpolated away, so you need to double it.

Escaping in template literals

The backslash is used for escaping inside template literals.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742403546a4437388.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信