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

206
Views
Regex to check if any latin letter except specific ones is present in string using javascript

My task is to check if string of an arbitrary length contains any latin letter except specific ones (in my case letters that match roman numerals (I,V,X,L,C) are not allowed)

So if no latin letter is present - the string is invalid, if specific character (mentioned above) is present - the string is invalid. Otherwise the string is valid.

Could someone help me to come up with proper regex for that condition?

Examples:

123 - invalid

123 aAA - valid

ABD - valid

AAa ddDD zzZz - valid

AXXXA - invalid

IV abc - invalid

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

0

This is a standard RegEx requirement, build a character class of all the characters you want to match. From your question this RegEx should do it for you: /^[^CDILMXV]*(?:[ABE-JKN-UWY-Z])+[^CDILMXV]*$/i

Note: I am allowing for more roman numerals than you had in your post, if that.s not what you need adjust accordingly.

The RegEx must have at least one allowed latin character (the middle part (?:[ABE-JKN-UWY-Z])+ and there must be no disallowed latin characters before or after the middle match (the [^CDILMXV]* at the start and end)

This should match all of your inputs.

about 4 years ago · Juan Pablo Isaza Report

0

This should be it. First part (?=.*[a-z]) checks for latin letters, and [^XLVCI] mathes anything besides these characters.

let string1 = '123'
let string2 = '123 aAA'
let string3 = 'ABD'
let string4 = 'AAa ddDD zzZz'
let string5 = 'AXXXA'
let string6 = 'IV abc'

let regex = /^(?=.*[a-zA-Z])[^XLVCI]+$/

let result = string1.match(regex)

console.log(string1.match(regex))
console.log(string2.match(regex))
console.log(string3.match(regex))
console.log(string4.match(regex))
console.log(string5.match(regex))
console.log(string6.match(regex))

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!