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

189
Views
How to check if a string contains at least one letter in JavaScript?

I am on validation work. this is my code

if (pwd.match(/[A-Za-z]/)) {
      $("#pwd-complexity-letter").html(good); 
      console.log("pwd complexity  invoked");
}

but this code has checked every string that I am passing through 'pwd'. For example, if I pass numbers or special char code become invoked and satisfying my input has at least one letter. how can I solve this please help. the problem is still on the small letter [a-z] checking. Capital letter only satisfy capital inputs. but the small letter has passed every string.

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

0

For this you can use javascript regexp

var regexp = /^[a-z]+$/i;
if (regexp.test(pwd)) {
  $("#pwd-complexity-letter").html(good); 
  console.log("pwd complexity  invoked");
}
about 4 years ago · Juan Pablo Isaza Report

0

You can use regexp for it:

[a-z] will match any letter from a to z while /i will tell the regex to be case insensitive.

if (isPasswordValid("a1235@")) {
  console.log("Password valid")
} else {
  console.log("Password invalid")
};


function isPasswordValid(psw) {
  let regex = /^[a-z]/i
  return regex.test(psw) // you test if the passed string match the regex, if it does the function will return true else false.
}

You can use a function like isPasswordValid and pass your psw value in it to check if it's valid or not

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!