Machine learning example on numeric

Need to know which Machine learning model will be helpful which tells a number is valid or not if it has to take only 7 digits and return valid and if it is more than seven or if any special characters or character found in it should recognize the value as invalid

3456789 valid
We34217 invalid
**""’ invalid

Any thoughts on it which model we can use on it