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.
this.value = this.value.replace(/[^а-я0–9.,!?’“\s]/i, ““);
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.