Reputation: 329
I need to write a JavaScript program where it validates input.
Requirement:
I was able to write regex for the first two points, but I couldn't include the final point. here is what I have tried for the first two points.
input.match(^--NAME--(.*)$)
Upvotes: 0
Views: 1089
Reputation: 198476
You can use a lookahead assertion for length:
/^(?=.{50})--NAME--.*$/
From start, at least 50 characters, starting with --NAME--
.
Upvotes: 1
Reputation: 13265
Use pattern /^--NAME--.{42,}$/
.{42,}
- This will match 42 or more characters. The total will be 50 including the prefix (--NAME--
).
const regex = /^--NAME--.{42,}$/
console.log(regex.test("--NAME--C$#V"))
console.log(regex.test("--NAME--C$#Vf34F#$f3ftbalc93h34vs#$3gfsddn;yu67u4g3dfvrv34f3f3ff"))
Upvotes: 2