kazupon / vue-validator

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

Сheck for empty string #271

Closed serega270 closed 8 years ago

serega270 commented 8 years ago

Hi guys, can't figure out how to check with vue-validator model to an empty string

<validator name="validation">
  <input type="text" v-model="name" v-validate:name="{ required: {rule: true}}">
  {{$validation.name | json}}
</validator>

If you enter only spaces, //valid": true

I can do it manual check using .trim(), but I would like to know how to do vue-validator

Is there any way to do this?

vue-validator: 2.1.3

kazupon commented 8 years ago

You can use the pattern validator. see the below url http://jsfiddle.net/kazupon/5um0mjta/1/

serega270 commented 8 years ago

Sorry, but the pattern validates only the letter 's', аnd do not miss anything else. In your example, it is also seen http://jsfiddle.net/kazupon/5um0mjta/1/ Maybe there is a different pattern, but I can not find the right

vip30 commented 8 years ago

http://jsfiddle.net/5um0mjta/2/

Now if the input is whitespace, it will be valid. Is that what you need?

serega270 commented 8 years ago

No. Sorry if I incorrectly asked the question. I need to see if the user entered only whitespace and no other characters then valid = false

vip30 commented 8 years ago

http://jsfiddle.net/5um0mjta/3/

pattern: '/\\S/' }"

Actually I think the main point is the pattern validator is working as expected.

serega270 commented 8 years ago

Yes, this pattern works as I need. Thank you