htmldesign-patternstextinput

Regular expression for detecting first name and/or last name


Please help me to build a pattern in the text input field like that,

<input name="BusinessOwner" type="text" id="BusinessOwner" pattern="?">

But the rule is that this input field only allow English Small letter and/or Capital letter(include/Exclude space) and no Numeric Digits. So according to the rule,

Adam Smith => valid
adam => valid
AB CD => valid
abcd12 => Invalid
abcd 12 => Invalid

Please help me to build the pattern.


Solution

  • I recommend you to use this pattern:

    ^([A-Za-z]+[,.]?[ ]?|[A-Za-z]+['-]?)+$
    

    Final:

    <input name="BusinessOwner" type="text" id="BusinessOwner" pattern="^([A-Za-z]+[,.]?[ ]?|[A-Za-z]+['-]?)+$">
    

    Hope this would be helpfull.