Home > Blockchain >  How to Create Pattern for Textbox?
How to Create Pattern for Textbox?

Time:01-06

I have Textbox and I want to Allow Numeric value or Only Letter 'A'. Which Pattern will prefer for this?

<input type="text" id="txt" name="txt" pattern="^[0-9][A]*$" title="Allow numeric value or only Letter 'A'" required>

CodePudding user response:

This should work

<input type="text" id="txt" name="txt" pattern="[\dA]*" title="Allow numeric value or only Letter 'A'" required>

This is good place to learn Regex

CodePudding user response:

Try with this regex - "^([0-9]{1,})|(A)$" Basically means either allow numerical value of any length ({1,}) or just A

<input type="text" id="txt" name="txt" pattern="^([0-9]{1,})|(A)$" title="Allow numeric value or only Letter 'A'" required>

Your regex meant allow one [0-9] value and 0 to any occurrences of A. So it would match patterns like - 0, 1A, 1AA etc.

  •  Tags:  
  • Related