SMS client side validation – two different character limits on cyrillic and latin

I have a SMS text field where by requirement I need to limit my character limit depending on the type of language:

160 limit for Latin language
80 for Cyrillic

I have read about character classes and I found this topic interesting.

regular expressions with the Cyrillic alphabet?

I could use @"p{IsCyrillic}+" for Cyrillic and @"[p{Ll}p{Lt}]+" for Latin.

My question is how to I set the different validations for both of those?

I am using Vuelidate and here is my piece of code:

    <h4> SMS </h4>
 <div class="form-group row">
    <label for="Headline" class="col-sm-2 col-form-label">Text</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="smsText" v-model='$v.smsText.$model'>
    <div class="alert alert-danger" id="bodyTextError" v-if="$v.smsText.$error">
      SMS text should not be empty and should not be more than 160 characters!


import { required, maxLength } from 'vuelidate/lib/validators'
export default {
  name: 'Sms',
  data () {
    return {
      smsText: ''
  validations: {
    smsText: {
      maxLength: maxLength(160)
  mounted () {
    this.$emit('update:smsText', this.$data)

Source: Vue – Stack Overflow

November 29, 2021
Category : News
Tags: regex | Vue.js | vuelidate

Leave a Reply

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

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.