简体   繁体   中英

i want to prevent user from input whenever they put 0 using regular expression (regexp)

I'm using this code for html:

<input pattern="/^[1-9]\d*$/g" id="num-input" type="number" min ="0" class="form-control number" placeholder="Input numbers here" aria-label="Input number here" aria-describedby="btn-generate">

and this is in my script.js file:

function numIntoUnits() {
    let num = $('#num-input').val()
    // let full_name = $("#register-full-name").val()
    console.log(num)
}

it still shows the input numbers with zero

Your regex look overcomplicated. /^[1-9]+$/ should do just fine.

Furthermore, setting min to 1 instead of 0 should suffice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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