Jump to content

Recommended Posts

Posted

In some of our Contract fields we have a Regex like this:

^(.|){0,255}$

This is meant to limit the number of characters to 255. If it fails (ie more than 255 characters) then we output an error message. That is all good.

BUT some of our users have found that if they enter 1 character, then return and then enter another character - they get the error message. see below

image.png.d70c2600585802d6111a622242d1ba9a.png

I don't understand this or how I stop it. Can anyone help please?

Posted

I think this is because your REGEX states "A line of up to 255 characters" and the input is "Two lines, not exceeding a total of 255 characters" so I'd suggest removing the initial caret.

Posted

I'm not sure removing the ^ and $ will work in this case (could be wrong) but I would suggest using \s\S to match all non-whitespace and whitespace characters to achieve the same (I think this is usually the preferred way with JavaScript)

^[\s\S]{0,255}$

 

Posted

Many thanks @Met. This is similar and achieved the same goal

^(.|\s){0,255}$

Inside the () (standard brackets) means

. (anything except a line break)

| (OR)

\s (whitespace character which includes space, tab, carriage return)

ie basically anything! Which I think is the same as [\s\S] in square brackets

I really don't like Regex!!!!

Posted

After testing, simply removing the caret worked fine in my Instance.

image.png

image.png

Also, I noticed on a second look that the "pipe" after the period was redundant as well - it wasn't breaking anything, it was just pointless.

image.png

Posted
2 hours ago, Steve Giller said:

After testing, simply removing the caret worked fine in my Instance.

image.png

image.png

Also, I noticed on a second look that the "pipe" after the period was redundant  as well - it wasn't breaking anything, it was just pointless.

image.png

The problem with this is that it will match regardless of how many characters you have without the anchors (^ $). If you try changing it to {0,5} does it error out when you put in more than 5 characters? Without the anchors it is just checking for 0 or more characters at any point in the string

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...