methods: {
isEmail(e) {
let char = String.fromCharCode(e.keyCode); // Get the character
if(/^[A-Za-z0-9*,&,@]+$/.test(char)) return true; // Match with regex
else e.preventDefault(); // If not match, don't add to input text
},
<input type="email" v-model.trim="$v.email.$model" :class="{'is-invalid': validationStatus($v.email)}" class="input-section" placeholder="Enter your company email ID" :maxlength="maxemail" v-on:keypress="isEmail($event)">
<div v-if="!$v.email.required" class="invalid-feedback">The email field is required.
</div>
<div v-if="!$v.email.maxLength" class="invalid-feedback">30 characters {{
$v.email.$params.maxLength.min }} only</div>
My issue is that at present the textbox above is only accepting alpha characters (A to Z and z to A). However, I need it to accept alphanumeric characters (i.e A to Z, a to z, 0 to 9 and special characters like *,&,@). How can I modify the code above to achieve this?