简体   繁体   English

如何使用 HTML 模式属性允许两个输入值

[英]How to allow two input values using an HTML pattern attribute

I'm looking to constrain user input using an HTML pattern attribute on a text input, I didn't want to use a select or radio buttons tag for design purposes.我希望在文本输入上使用 HTML 模式属性来限制用户输入,我不想出于设计目的使用 select 或单选按钮标签。 I tried many approaches but none of them allowed me to get to what I want.我尝试了很多方法,但没有一种能让我得到我想要的。

 <form action="" method="post"> <input type="text" class="study" name="study" placeholder="Enter your year of study L1-3,M1-2 " pattern="[LlMm]+[1-2-3]" maxlength="2" title="only L1,L2,L3 and M1,M2 are allowed" required> <button name="submit" class="btn" type="submit">Register</button> </form>

found the answer [L]{1}[1-3]|[M]{1}[1-2] using https://regex101.com and using logical or enter image description here找到答案 [L]{1}[1-3]|[M]{1}[1-2] 使用https://regex101.com并使用逻辑或在此处输入图像描述

Use this pattern: [LM]{1}[0-9]{1}使用此模式: [LM]{1}[0-9]{1}

You can check if this work for you with this tool: https://regex101.com您可以使用此工具检查这是否适合您: https://regex101.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM