Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello forum! Hello Kamran!

I make a form for russian public...I guess, but I am not sure, that validator='alpha' would not prevent input of russian letters?

The whole document has charset=UTF-8, if that is relevant anyhow.

Another validator that I would like to use for phone number input is 'non_negative_integer', but I would like to add the sign "+" to the 0-9 numbers.

And for the date entry, I would like to add a dot "." to the validator for 0-9 numbers, so that only this kind of Date can be entered: 12. 12. 2012 (not with / or with -).

Would that be possible somehow?

Thanks in advance

Tanja
Hi Tanja,

The validator='alpha' allows only a-zA-Z characters, so indeed it wouldn't allow Russian characters to be inputted. To allow Russian (or any other non-latin language), we'll have to check for Unicode.

One of the validators supported by Couch is the regex validator. This is relatively more complex to setup but can cater to almost all conceivable requirements.
Making use of this validator, we can tackle all the three scenarios you mentioned.

Allowing Unicode Alpha only:
Code: Select all
<cms:input type="text" size="10" maxlength="40" name="alpha_test" 
    validator='regex=/^\pL++$/uD'
    validator_msg='regex=Only alphabets allowed'
    required='1' />

Allowing Unicode AlphaNumeric only:
Code: Select all
<cms:input type="text" size="10" maxlength="40" name="alpha_test" 
    validator='regex=/^[\pL\pN]++$/uD'
    validator_msg='regex=Only alphanumerics allowed'
    required='1' />

Allowing '+' with integers:
Code: Select all
<cms:input type="text" size="10" maxlength="40" name="number_test" 
    validator='regex=/^\+?[0-9]+$/'
    validator_msg='regex=Only positive integers allowed'
    required='1' />

Checking for dd.mm.yyyy Russian format date:
Code: Select all
<cms:input type="text" size="10" maxlength="40" name="date_test" 
    validator='regex=/^(?:0[1-9]|[12][0-9]|3[01])\.(?:0[1-9]|1[012])\.(?:19|20)\d\d$/'
    separator='#'
    validator_msg='regex=Incorrect date format. Should be dd.mm.yyyy'
    required='1' />

Hope this helps. Do let me know.
Hello Kamran!
Thanks!!!! That helps a lot!!!

I do not understand the part of the code after regex, I guess it is php that I have no slightest idea of.
I could only copy and past the code.

This is great help for future work too....I have just seen that validator=alpha would not allow german characters too ( öäü).

Just one thing more, if it is possible:
The code that allows positive alphanumeric numbers seems to allow only one "+". Would it be possible to change it so that it allows ++? So it can stay for the international preselection phone code which is 2 numbers...

thanks in advance best regards

Tanja
3 posts Page 1 of 1