JSFiddle - React, Tailwind, and code Playground

by 20yco

JavaScript

var name = 'qwerty';
var mobile = '93874678';

var pattern = /^[a-zA-Z]+$/;
if(pattern.test(name)){
 console.log('match');
//code if there are only letters
} else{
 console.log('no match');
}

var check = /^[0-9]*$/;
if(check.test(mobile)){
 console.log('match');
//code if there is only numbers
}else{
 console.log('no match');
}