admin管理员组文章数量:1026073
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.
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.
Share Improve this question asked Feb 12, 2020 at 16:25 UnluckyLADUnluckyLAD 1893 silver badges21 bronze badges 1- 1 You are not returning any string, you are returning the validation result, true or false – Ian Vasco Commented Feb 12, 2020 at 16:30
1 Answer
Reset to default 3Have you tried wrapping your regexp in new RegExp()
For example:
const nameRegex = new RegExp(/^[a-z ,.'-]+(\s)([a-z ,.'-])+$/i);
if (nameRegex.test(inputValue)) {
doSomething();
}
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.
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.
Share Improve this question asked Feb 12, 2020 at 16:25 UnluckyLADUnluckyLAD 1893 silver badges21 bronze badges 1- 1 You are not returning any string, you are returning the validation result, true or false – Ian Vasco Commented Feb 12, 2020 at 16:30
1 Answer
Reset to default 3Have you tried wrapping your regexp in new RegExp()
For example:
const nameRegex = new RegExp(/^[a-z ,.'-]+(\s)([a-z ,.'-])+$/i);
if (nameRegex.test(inputValue)) {
doSomething();
}
本文标签: javascriptusing REGEX on textInput in react nativeStack Overflow
版权声明:本文标题:javascript - using REGEX on textInput in react native - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745632876a2160269.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论