Q:

HTML validation rules with regex

I need to validate a code format:

Need to be 10 characters
A mix of letters and numbers
At least 1 letter from a-f

and I write:
<input maxlength="200" type="text" name="code" id="code" required="required" class="form-control input-lg"  pattern="[a-fA-F0-9]{10}" title="Wrong Code" placeholder="Security Code" />

so my pattern is pattern="[a-fA-F0-9]{10}" but HOW I can add rules that at least 1 letter from a-f is required?

A:

You could use a positive lookahead (?= to assert that what follows contains at least 1 occurance of [a-fA-F]
Updated version suggested by Wiktor Stribiżew
(?=[0-9]*[a-fA-F])[a-fA-F0-9]{10}
Explanation about the positive lookahead (?=[0-9]*[a-fA-F])

(?: Non capturing group

[0-9]* Match zero or more times a digit
[a-fA-F] Match a-f in lower or uppercase

) Close non capturing group

<form>
  <input maxlength="200" type="text" name="code" id="code" required="required" class="form-control input-lg" pattern="(?=[0-9]*[a-fA-F])[a-fA-F0-9]{10}" title="Wrong Code" placeholder="Security Code" />
  <input type="submit" name="submit">
</form>

