Our website has a form that requires* a signature field to be filled in to complete the form submission. Our problem is that we need to set a condition that disallows numbers, and symbols. We also need to disallow someone from placing their cursor in the signature field box and hitting the space bar as that is also currently accepted as a successful signature.
So to conclude we only want the signature field to be able to accept a first and last name and that would usually include a space between the two names and not allow people to ad anything else.
Thanks in advance if anyone could be helpful on this....
This is what we were trying to use but it disallowed any text in the signature field
function hasUnwantedCharacter(myString) {
return /[`~!@#$%^&*()-_+{}[\]\\|,.//?;':"]/g.test(myString);
}
function hasUnwantedCharacter(myString) {
return /[`~!@#$%^&*()-_+{}[\]\\|,.//?;':"]/g.test(myString);
}
Tried the above but it disallowed any text as well as symbols, numbers and spaces so obviously it was not correct.
Thanks for your reply Regex101 much appreciated. I have add your suggestion to the following code
function hasUnwantedCharacter(myString) {
return /^[A-Za-z]+ [A-Za-z]+$/gm.test(myString);
}
$typeField.blur(function(e) {
// console.log($typeField.val());
let $typeFieldValue = $typeField.val().trim();
if ($typeFieldValue == "" && !hasUnwantedCharacter($typeFieldValue)) {
signaturePad.clear();
tCtx.font = "50px Kalam";
tCtx.fillText($typeField.val(), 20, 80);
tCtx.fillStyle = "black";
$hiddenInput.val(tCtx.canvas.toDataURL());
}
});
But my form still doesn't accept spaces, I can do the "StackOverflow" and "StackOverflow" but not "Stack Overflow".
I don't have that much knowledge of javascript so any help is greatly appreciated. Thanks guys.