Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

using REGEX on textInput in react native

$
0
0

I can't seem to make my regex work so i think I must be doing something wrong. If anyone could help me out that would be great.

here is my regex function

let validatePlate = (plate) => {
  var re = /(^[A-Z]{2}[0-9]{2}\s?[A-Z]{3}$)|(^[A-Z][0-9]{1,3}[A-Z]{3}$)|(^[A-Z]{3}[0-9]{1,3}[A-Z]$)|(^[0-9]{1,4}[A-Z]{1,2}$)|(^[0-9]{1,3}[A-Z]{1,3}$)|(^[A-Z]{1,2}[0-9]{1,4}$)|(^[A-Z]{1,3}[0-9]{1,3}$)|(^[A-Z]{1,3}[0-9]{1,4}$)|(^[0-9]{3}[DX]{1}[0-9]{3}$)/

    return re.test(plate);
};

and I use it in textInput as follows:

<TextInput
onChange={validatePlate}
editable={true}
}}>
Hello
</TextInput>

It still allows special characters, etc.

FYI: The regex is for filtering UK numberplates.


Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>