Developer forum

Forum » PIM » Validation Patterns on Product Category Fields

Validation Patterns on Product Category Fields

Barend Mosch
Reply

Hi!

I've been experimenting with the possibilties of adding validation to either text and integer fields. While surfing the forum and after testing a bit myself, Ive noticed that validation patterns are not working correctly. It seems that the validation patterns have no affect on integer fields. Even a simple regex that accepts positive numbers: 

  • ^\d+$

does not work.

Validation on text fields does not work either. A simple regex that only allows empty strings OR strings with 6 or more characters: 

  • ^.{0,}$|^.{6,}$

still accepts a string with less than 6 characters (see attachment)

Is there something Im missing?

Kind regards,

Barend Mosch

Screenshot_2024-02-22_160525.png

Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Your regex is flawed as it shouldn't have ^ or $ in the middle. Try them out here: https://regex101.com/

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Try this: ^(\S{6,})?$

That allows 6 or more characters, and makes the whole thing optional with the ?

Imar

 

Votes for this answer: 1
 
Barend Mosch
Reply

Hi!

Yes, this seems to work, many thanks!

I found that 

  • ^$|^.{6,}$

Also does the trick, but this includes whitespace characters as wel, which might not be wanted.

How about integer and decimal defined fields. I tried a simple "Only accept number 1" scenario with ^1$
Is there a solution for this?

Kind regards,

Barend Mosch

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Barend

If you look at how patterns are handled on MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern

So to only allow the input '1' you regex should just be '1' resulting in this markup:

<input name="fieldname" type="text" pattern="1" required />
 
Barend Mosch
Reply

Hi Nicolai,

Apologies for the late reaction

The validation issue on Integer and Decimal field remains active I'm afraid. Using the same setup (only allow 1), it works for text fields, but not on integer/decimal fields. 

 

Where:

  • test decimal: Decimal field
  • test integer: Integer field
  • test text: Text(50) field


Regex used:


Regex tried:

  • 1
  • [1]
  • ^1$
  • ^[1]$
  • '1'

None worked, is there some 'number' specific rule I'm missing regarding validation patterns?

Cheers in advance & kind regards,
Barend Mosch, Bluedesk

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

As you see the validation options are hidden for the field types in definition of product custom fields now (forum). The same feature should be implemented in category fields, probably. So, it is under discussion now, a final result will be provided here later. Sorry for enconviniece.

BR, Oleg QA 

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

New task #19092 task has finally been created against the issue. Thanks for finding.

BR, Oleg QA

 
Barend Mosch
Reply

Hi Oleg!

Thanks for replying. Good to know its on the radar.

Kind regards,

Barend Mosch, Bluedesk

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Barend

The problem #19092 regarding Field validation has now been fixed in Dynamicweb version 9.17.5

You can get this version from the download section https://doc.dynamicweb.dk/downloads/dynamicweb-9

Sorry for any inconvenience this may have caused

Kind Regards
Care Support
Kristian Kirkholt

Votes for this answer: 1
 
Barend Mosch
Reply

Hi Kristian!

No worries, this is good news!

I will begin testing asap, thanks for letting me know.

Kind regards,

Barend Mosch, Bluedesk

 
Sigurd Nejrup
Reply

I'm still experiencing a similiar issue regarding field validation in DW 9.17.9 on both product fields and product category fields.

There is no pattern attribute generated:

So any input will pass, only limited by the field type.



 

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

I was not able to reproduce the issue using other valid pattern "^(\S{6,})?$" mentioned above. See video about my test.

Oleg QA

 
Sigurd Nejrup
Reply

Hi Oleg, thanks for getting back to me.
It's a rather fresh installation with few modifications made, but I'll try a fresh installation anyway and will get back to you if the issue persists.

 

You must be logged in to post in the forum