At the momemnt I'm using this regular expression to validate address
(!/^[A-Za-z]/i.test(street))
When I use address like this - Esterwergen - it works.
But when I added the sign before the title - 'Esterwergen - it shows my error.
Ho I can modify my RegEx and allow to use this sign before the name?
To allow an optional leading ', you'd change your regexp from
/^[A-Za-z]/
to
/^'?[A-Za-z]/
where the ? means "zero or one times".
If you want to allow the ' anywhere in your string,
/^['A-Za-z]/
would do the trick.
In addition, be sure that you realize that you're only checking the first character of the string as it is.
Right now you will allow Ester9ui4y6ewigkdlLNDSKJ#€=# :::.
To constrain that, you'll need the + quantifier and the $ (end-of-string) anchor.
/^[A-Za-z]+$/
Lets see what is your RegExp targeting:
/^[A-Za-z]/i
^: Asserts position at start of the string.
[]: Match a single character depending on what's inside.
A-Z: Match uppercase letters from A to Z.
a-z: Match lowercase letters from a to z.
i: Case-insensitive.
Consider this:
Using [A-Za-z] along with i flag is redundant. Use /^[a-z]/i or /^[A-z]/ instead.
Using [a-zA-Z\u00C0-\u00FF] for example extends matching to latin characters using UNICODE syntax. See full UNICODE reference here.
Use /^['a-z]+/i to allow ' anywhere in the string.
Use /^'?[a-z]+/i to allow ' only at the beginning of the string. ? means '1 time or 0 times'.
To play around with RegExp you can use tools like this.