pepperstreet VIP
Total posts: 3,832
16 Apr 2014 17:25

Hello, any RegEx guru here?

I wanted to add a custom validation to a text field for IBAN and BIC. I found misc RegEx snippets on the web. One source is here: Examples

I tried the following example from mentioned URL:

All IBAN check

[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}

In regards of Cobalt it just works fine by copying and pasting in the respective field parameter :)


Related Question

Now i wanted to use the same validation in CB / CommunityBuilder text field. Actually I am pretty firm in CB, but never used the custom RegEx validation. It is slightly different to Cobalt, and the tooltip shows a simple example and syntax i.e.:

Simple check for "only numbers". Hence the pre- and suffix part:

/^[0-9]*$/

How does this apply to my IBAN example?! I tried to modify and add it like so:

/^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}*$/

It does not work. :(

Am I totally wrong? Any clue or help is appreciated.

Last Modified: 21 Apr 2014


Sergey
Total posts: 13,744
17 Apr 2014 08:53

I need IBAN example. because to me it is always difefrent. In our country IBANs are all only digits. So /^[0-9]*$/ would work just fine. May be lenths restriction in addition /^[0-9]{10}$/.


pepperstreet VIP
Total posts: 3,832
17 Apr 2014 14:01

Sergey I need IBAN example. because to me it is always different. In our country IBANs are all only digits.

Yes, i know. I guess my previous example is a basic common check for allowed characters (as it is mentioned in the name "all countries").

So, it is not a real "validation". More a help to get a proper input format from users, without nonsense characters.

If you google for IBAN format and validation, there is also a "modulo" validation. Obviously not for this RegEx question/issue.

So /^[0-9]*$/ would work just fine. May be lengths restriction in addition /^[0-9]{10}$/.

My main question is more about the general syntax... and what is the meaning and right usage of /^ and *$/


Sergey
Total posts: 13,744
18 Apr 2014 05:13

^ means validate from the begining of the string and $ means to the end. For example you want to find if string ends with png fo find only png pictures.

/png$/

/ are enclose. It can be also #. So next 2 are identical

/^[0-9]*$/
#^[0-9]*$#

pepperstreet VIP
Total posts: 3,832
18 Apr 2014 23:25

Sergey I need IBAN example. because to me it is always difefrent.

wikipedia page with format descriptions


pepperstreet VIP
Total posts: 3,832
18 Apr 2014 23:32

Sergey ^ means validate from the begining of the string and $ means to the end

Thanks. I see. Now, I can almost read the example snippet ;) :D

[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}

Still not sure what the ? and the ending part {0,16} means.

What is the question mark?

0,16 is NO or MAX SIXTEEN?


Sergey
Total posts: 13,744
21 Apr 2014 07:51

? is may be yes may be no.

[0-9]{4} - 4 times [0-9]{2,4} - 2-4 times [0-9]* - zero or more times [0-9]+ - one or more times [0-9]? - zero or one time. Optional character.

For example

^(https?:) - string starts with http: or https: as s is optional. And starts because ^.

Replay Topic
Uploading
Click here to upload and insert file from you hard drive: (png, gif, jpg, jpeg, zip, txt, rar)
Powered by Cobalt