gpt4 book ai didi

javascript - Javascript 中输入前导 "000"

转载 作者:行者123 更新时间:2023-12-02 16:37:22 26 4
gpt4 key购买 nike

parseInt("09", 10) // 9 in this way it will just remove the leading 0 

但我想创建一个程序,如果用户输入一个带有前导零的数字,输出将无效

最佳答案

function test(input) {
return !/^0.*[0-9]/.test(input);
}

// false
console.log( test("01") );

// true
console.log( test("1") );

// false
console.log( test("00") );

// true
console.log( test("0") );

关于javascript - Javascript 中输入前导 "000",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27804497/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com