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:

<template>
<div>
<br>
    <h4> SMS </h4>
<form>
 <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>
    <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!
      </div>
  </div>
</form>
</div>

</template>

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

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.