hidden
hidden

Reputation: 3236

Regular expression, required field only with alphanumeric

So how do I add that it should not have empty field in this same line including my other validation for alphanumeric reg ex.

^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$

I tried this and didn't work

^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$ | /\S/ 

This is for validation controls

<asp:RegularExpressionValidator id="userLocationValidation" runat="server" 
      ControlToValidate="userLocation" 
      ValidationExpression="/\S/"
      ErrorMessage="Only use letters from the english alphabet a-z">                                                               
  </asp:RegularExpressionValidator>    

Upvotes: 0

Views: 6977

Answers (2)

Mrchief
Mrchief

Reputation: 76218

Use:

^[A-Za-z0-9 _]+[A-Za-z0-9][A-Za-z0-9 _]*$

The '+' says one or more, so empty fields will fail.

Upvotes: 3

zellio
zellio

Reputation: 32484

^[a-zA-Z0-9 _]+$

+ means at least one

if you mean at least one not white-space character something like

^[a-zA-Z0-9 _]*[a-zA-Z0-9_]+[a-zA-Z0-9 _]*$

Upvotes: 0

Related Questions