JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text"/>

CSS

.error{
 background-color:#ffa8a4;
}

JavaScript

$(document).on('keyup','input',function(e){
    
    var reg = new RegExp('[0-9]./-');
    var val = $(this).val();
    if(val!=''){
         if(val.search(reg)!=-1){
            console.log('No problem with:'+val)
        }else{
            $(this).addClass('error',100,function(){
				 $(this).removeClass('error',500);
			});
            if(e.which!=8){
                event.preventDefault();
            }
            console.log('Problem is with :'+val)
        }
    }
});