admin管理员组文章数量:1336397
I have a simple form for signup to my app in React Native. In one step, im validate the name of user is full. Initially, i writing a regex for validate characters and size min and max, but i need validate of a structure of name, with the before rules.
Examples
Valid names: Luke Skywalker, Ben Skywalker, Lu Skywalker
Invalid names: L Skywalker, Luke
My regex start here:
const rule = /^[a-zA-Z ]{2,40}$/;
How i would should write this regex? Grouping these rules?
I have a simple form for signup to my app in React Native. In one step, im validate the name of user is full. Initially, i writing a regex for validate characters and size min and max, but i need validate of a structure of name, with the before rules.
Examples
Valid names: Luke Skywalker, Ben Skywalker, Lu Skywalker
Invalid names: L Skywalker, Luke
My regex start here:
const rule = /^[a-zA-Z ]{2,40}$/;
How i would should write this regex? Grouping these rules?
Share Improve this question asked Nov 13, 2019 at 4:21 DanielDaniel 251 silver badge7 bronze badges 2- Are there really only three valid names? Or, are the 3 names you gave just an example of the types of names which are valid? If the latter, then can you also tell us the logic for discerning a correct name from an incorrect one? – Tim Biegeleisen Commented Nov 13, 2019 at 4:25
- @TimBiegeleisen just examples. The rule consider two or more names, with 3 characters min and 40 maximum. – Daniel Commented Nov 14, 2019 at 2:51
1 Answer
Reset to default 7You can try the following as a start: ^[a-zA-Z]{2,40} [a-zA-Z]{2,40}$
const pattern = /^[a-zA-Z]{2,40}( [a-zA-Z]{2,40})+$/;
console.info(pattern.test('Luke Skywalker'));
console.info(pattern.test('Ben Skywalker'));
console.info(pattern.test('Lu Skywalker'));
console.info(pattern.test('Lu Saber Skywalker'));
console.info(pattern.test('Ben The Ghost Skywalker'));
console.info(pattern.test('L Skywalker'));
console.info(pattern.test('Luke'));
本文标签: javascriptHow to do validate full name in JS in React NativeStack Overflow
版权声明:本文标题:javascript - How to do validate full name in JS in React Native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742240384a2438794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论