I think you want to combine the beginning of a line once, then use Positive Closing - one or more of your letters, spaces or numbers, and then the end of the line.
/^[A-Za-z\d\s]+$/.test(linkTitle)
Tested with
var reg = /^[A-Za-z\d\s]+$/; ["Adam", "Ada m", "A1dam", "A!dam", 'sdasd 213123&*&*&'].forEach(function (str) { console.log(reg.test(str + "\n")); });
Shows true
, true
, true
, false
, false
Or if you want to allow blank lines, you can use the same RegEx, but with Clleure Kleene - zero or more letters, numbers or spaces
var regAllowEmpty = /^[A-Za-z\d\s]*$/; ["", "Adam", "Ada m", "A1dam", "A!dam", 'sdasd 213123&*&*&'].forEach(function (str) { console.log(regAllowEmpty.test(str + "\n")); });
note that forEach
will not work in older browsers - it's just for testing
Adam rackis
source share