How to make a textbox accept spaces in between words? regex?

So I have a textbox placed for when I ask a user to input their name.
Right now, users are able to enter a word, which is fine, but if they do two words it gives them an error.
I need a way for spaces to be accepted, but only if they come after words.
That way users aren’t able to insert a string consisting only of spaces.
“New Port Richey” should be allowed, but not “⠀⠀”

How would I be able to do this?

This is my code currently:

<<button Confirm>>
<<if $name is "">>
	<<replace "#textbox-error">>Please enter a name.<</replace>>
<<elseif /[^A-Z]/i.test($name)>>
	<<replace "#textbox-error">>Names may only contain letters.<</replace>>
<<else>>
	<<replace "#textbox-error">><</replace>>
	<<goto "Start.PickSettlementLocation">>
<</if>>
<</button>>
<br/>
<span id="textbox-error" style="color:#00FA9A;"></span>
<br/>

You can probably put a <<set $name to $name.trim()>> before your checking. String.trim will remove whitespace from both ends of the string, so if the user enters only spaces then you will end up with an empty string.

Also you’ll want to add a space character to your regular expression.

That should work, unless I’m forgetting something.

1 Like

Thank you!