I want to allow only letters and space in input box like "john deo". but the above doesn't work with below Regex and it is not allowing space.
<!DOCTYPE html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<label>full name
<input type="text" name="textfield" onkeydown="return /[a-z]/i.test(event.key)"
onblur="if (this.value == '') {this.value = '';}"
onfocus="if (this.value == '') {this.value = '';}"/>
</label>
</body>
</html>
change your regular expression like /[a-z, ]/i
<!DOCTYPE html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<label>full name
<input type="text" name="textfield" onkeydown="return /[a-z, ]/i.test(event.key)"
onblur="if (this.value == '') {this.value = '';}"
onfocus="if (this.value == '') {this.value = '';}"/>
</label>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With