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

138
Views
Javascript regex with below validation rules

Allowable characters:

  1. uppercase A to Z
  2. lowercase a to z
  3. hyphen
  4. apostrophe
  5. single quote
  6. space
  7. full stop
  8. numerals 0 to 9

validations:

  • Must contain alphabetic characters
  • Cannot have consecutive non alpha characters except for full stop followed by a space OR apostrophe can be followed by a space
  • Cannot have non-alphabetic characters at the start (except for apostrophe)
  • Can end with a full stop

I have a regex with the below validation. Use this as reference

/^(?=[a-zA-Z0-9`'. -]+$)(?!.*[0-9'` -]{2})[a-zA-Z'][^\r\n.]*(?:\.[ a-z][^\r\n.]*)*$/;

Need to add the below validations to the above regex

  1. Can end with a full stop
  2. An apostrophe can be followed by a space.

Examples Valid

  1. 'Andy
  2. Andy.
  3. Andy' De'Wall
  4. Andy. DeWa2e
  5. A2dy'

Examples Invalid

  1. 2Andy
  2. A2'ndy.
  3. Andy'-Wall
  4. Andy. DeWa23
  5. A24dy'
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could:

  • assert not 2 consecutive digits . ' or -
  • assert not a digit or hyphen or space followed by a space
  • assert at least a char A-Z a-z
  • start the match with either ' or a char A-Z a-z

For example

^(?!.*[0-9.'-]{2})(?!.*[0-9 -] )(?=[^A-Za-z\n]*[A-Za-z])[A-Za-z'][A-Za-z0-9.' -]*$

Regex demo

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!