HTML simple not blank pattern

后端 未结 2 1638
無奈伤痛
無奈伤痛 2020-12-29 03:52

I have a simple form and i want the submit button not to work for the conditions i give in the pattern, but if i leave it blank the submit works. how can i make the pattern

2条回答
  •  遥遥无期
    2020-12-29 04:42

    To prevent errors from showing on load, you can not use the HTML5 required attribute. You can use JavaScript. For example:

    if ( $('#form-password').val() === "" ) 
    {
        e.preventDefault();
    }
    

    Using HTML Patterns to match at least one:

    
    

提交回复
热议问题