Don’t get me wrong but this is the Ionic Framework forum.
This question should be asked at StackOverflow.
P.S. Like @junaidy told you use Regular Expressions. Learn them if you don’t know then, you can’t call yourself a developer if you don’t know how to use Regex.