How to use trimmed value for username validation

Hi, I want to allow the username to add either whitespace before or after text and for this not to be included in the validation and not add up to the character count. How can this be achieved with my current regex pattern?

<input id="text1" type="text" accept="text/plain" autocomplete="off" data-msg-min="" data-msg-equalto="" data-msg-unicodelettersonly="" data-msg-pattern="oops" data-rule-pattern="^[a-zA-Z0-9][a-zA-Z0-9]*([._-][a-zA-Z0-9]+){3,15}$" data-msg-maxlength="" data-msg-minlength="" maxlength="15">

With this regex “Usernames can be 3 to 15 characters long, must start with a letter or number & can include these three special characters . - _ but not consecutively.

So for example these inputs should only equal to 4 characters and be accepted value.

image

image

This will check that the string is between 3-15 characters, allows alphanumerical, spaces and the special characters ._-

^(?=.*[A-Za-z-._ ])[A-Za-z-._ \d]{3,15}$
1 Like

Hi thanks for the reply, I tried the regex it’s not quite right. The special characters can not be consecutive so faye.mcguire is accepted but faye.-mcguire or faye..mcuire is rejected. Then whitespace should only be leading or trialing but not in between any characters.

I need some operation like input’s value trimmed before validation, either with regex or wappler ui.

I think the suggestion @max_gb made in this thread, to use a hidden input, might be a solution.

1 Like

Thanks I will try.

Try:

^\s*(?!.*[\.\_\\ \-]{2}).*(?=.*[A-Za-z-._])[A-Za-z-._\d]{3,15}\s*$

In addition to my first example, this now should prevent consecutive special characters and allow a white space at the beginning or end

1 Like