[英]How to remove spaces, special characters and leading numbers with regex?
I want to create regex that can be used with jQuery that does below我想创建可以与下面的 jQuery 一起使用的正则表达式
I found most solutions for each point online, but I do not understand how to combine all 3. I will use this to alter a HTML form input when the form is submit.我在网上找到了每个点的大多数解决方案,但我不明白如何将所有 3 个组合起来。我将使用它来在提交表单时更改 HTML 表单输入。
Example someone writes '123 John' then it would change the input to just 'John' before submit.例如有人写“123 John”然后它会在提交之前将输入更改为“John”。 Or '123 John Is Me' becomes 'JohnIsMe' etc.或者“123 John Is Me”变成“JohnIsMe”等等。
Why combine them?为什么要把它们结合起来?
Let's assume a user types in something invalid.让我们假设用户输入了一些无效的内容。 Would it be better to say it's invalid, or would it be better to specifically say "cannot start with a number"?是说它无效更好,还是专门说“不能以数字开头”更好?
Test each restriction separately, and return a helpful error message to the user based on what, specifically, is wrong with their input.分别测试每个限制,并根据用户输入的具体错误向用户返回有用的错误消息。
(Also, don't just change what the user types. That's confusing and bad experience as well. Have the user correct it, by telling them what's wrong.) (另外,不要只是改变用户输入的内容。这也是一种混乱和糟糕的体验。让用户纠正它,告诉他们什么是错的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.