HTML5输入验证字母和数字 [英] HTML5 input validate letters and numbers

查看:471
本文介绍了HTML5输入验证字母和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • 接受小写字母

  • 大写字母已接受

  • 接受的号码

  • 接受减号字符



  • HTML到目前为止

     < input type =textpattern =[a-zA -Z0-9-]需要> 

    上面的代码不起作用。我猜我已经接近了吗?

    解决方案

    您实际上很接近:

      [a-zA-Z0-9  - ] + 
    ^

    您只需要这个 + 加量词,它告诉输入字段接受一个或多个您在字符类<$ c中列出的字符$ c> [] 。


    I need a pattern for a HTML5 form.

    • Lowercase letters accepted
    • Uppercase letters accepted
    • Numbers accepted
    • Minus character accepted

    HTML so far

    <input type="text" pattern="[a-zA-Z0-9-]" required>
    

    The code above does not work. I guess I'm close?

    解决方案

    You are pretty close actually:

    [a-zA-Z0-9-]+
                ^
    

    You just needed this + plus quantifier, which tells the input field to accept one or more the characters you have listed in the character class [].

    这篇关于HTML5输入验证字母和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆