How to require only Cyrillic input


A case from the practice:

You have an e-commerce website integrated with the local delivery company. The thing is that all the address’ fields should be filled in Cyrillic as this is the expected input. Any Latin input will break the delivery service. So you need to make sure that only Cyrillic characters are used.

Here is the example JavaScript code using a regular expression that is “protecting” the input field form non-Cyrillic input.

 

 

You can check it how it works on this jsfiddle.

What actually it does:

  • each typed character that is not included in the regex above is deleted form the input.

That’s all, but don’t forget that there should be also server side validation.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *