1

I am trying to create an input for a company name using jQuery. I am also using the Bootstrap Validator plugin by 1000hz in order to add validation for this input. I am specifically trying to use the "pattern" attribute in order to validate the input with a regex. An example of what I'm trying to accomplish is below:

var name = "<input type='text' pattern='^[a-zA-Z0-9]+(?:[&'\-. ]+[a-zA-Z0-9., ]+)*$'>";

....

$("#list").after(name);

I'm trying to include an apostrophe into the pattern so that a company name like "McDonald's" would be valid. However, since the pattern is within single-quotes the symbol winds up being treated as the end of the pattern string. I can't use double-quotes because they're being used for the variable, and trying to use escape characters doesn't change it from being treated as the end of the string.

Does anyone know how I go about fixing this?

Alexander
  • 999
  • 1
  • 9
  • 18

0 Answers0