kazupon / vue-validator

:white_check_mark: Validator component for Vue.js
MIT License
2.19k stars 431 forks source link

pattern reg parse bug #259

Closed hiyuki closed 8 years ago

hiyuki commented 8 years ago

vue & vue-validator version

1.0.24, 2.1.3

Reproduction Link

Steps to reproduce

v-validate:verify="{required:true,pattern:'/^\d{4}$/'}

What is Expected?

The pattern parsed correctly and validate for 4 numbers

What is actually happening?

the pattern parsed as /^d{4}$/ and only valid with input 'dddd'

kazupon commented 8 years ago

Sorry for my late reply.

Thanks for your reporting! I'll try to fix in v3. In v2, You can avoid with the custom validator. See the below documentation URL http://vuejs.github.io/vue-validator/en/custom.html

suweiwua commented 8 years ago

I think it's not a bug. You should try v-validate:verify="{required:true,pattern:'/^\\d{4}$/'}

kazupon commented 8 years ago

Yeah, Yor're right. https://jsfiddle.net/kazupon/8m1d2847/2/

reverland commented 8 years ago

but, maybe the doc for v2 should be updated to address this problems?

the example still use \d instead of \\d.

https://github.com/vuejs/vue-validator/blame/dev/docs/en/api.md#L93

https://github.com/vuejs/vue-validator/blame/dev/docs/en/api.md#L517