Javascript disable space key for change password textboxes

心已入冬 提交于 2019-12-07 14:22:44

问题


,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


回答1:


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.




回答2:


                        <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.



来源:https://stackoverflow.com/questions/18780304/javascript-disable-space-key-for-change-password-textboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!