Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
How to allow use sign ' with regular expression?

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?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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]+$/
about 4 years ago · Juan Pablo Isaza Report

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!