Javascript disable space key for change password t

2019-05-15 20:30发布

,Hi all,

var veri = {
YeniSifreTextBox: $('#YeniSifreTextBox_I').val(),

YeniSifreTekrarTextBox: $('#YeniSifreTekrarTextBox_I').val(),
};

if (veri.YeniSifreTextBox == '' || veri.YeniSifreTekrarTextBox == '') {
alert("Password Can not be empty!");
}
else if (veri.YeniSifreTextBox != veri.YeniSifreTekrarTextBox) {
alert("Passwords dont not match !");
}

I can control password can not be empty and passwords dont not match with above codes.

I want to disable to enter space key while user write password.

User must never use space in keyboard inside of 2 textboxes.

1.textbox YeniSifreTextBox_I

2.textbox YeniSifreTekrarTextBox_I

2条回答
Summer. ? 凉城
2楼-- · 2019-05-15 20:36

You can use the below javaScript code to block the space key,

function RestrictSpace() {
    if (event.keyCode == 32) {
        return false;
    }
}

HTML

<textarea onkeypress="return RestrictSpace()"></textarea>

Hope this helps you.

查看更多
唯我独甜
3楼-- · 2019-05-15 20:37
                        <input type="number" 
                           id="cardNumber"
                           name="cardNumber"
                           required
                           onKeyDown="if(event.keyCode === 32)
                           return false;">

You can implement the same functionality, without creating a custom function.

查看更多
登录 后发表回答