Gossamer Forum
Home : Products : DBMan : Customization :

Validate Records

Quote Reply
Validate Records
Dear Forum, I have another question. I want to validate a record that a user adds. I found a script/mod
but that's complex. I only want to validate a record if it doesn't contains a letters 'abcdef...' and starts with a '+' because it's a record for telephone numbers.


Quote Reply
Re: Validate Records In reply to
You're just wanting to validate the input? If so, we need to come up with a regular expression for you to use.

What format is acceptable?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Records In reply to
Yes i just want to validate a input. I want to validate a telephone number. The input must starts with a '+' after that is must contains at least 10 digitis and no letters (characters)

example : '+31012345678'

Thanks for all your help JPDeni to the forum.

Quote Reply
Re: Validate Records In reply to
You're welcome. Smile

In your .cfg file, in the last section for the definition of the field, use

'^\+\d{10}$'

This will require that the field starts with a + and has exactly 10 digits following it.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Records In reply to
Thanks for your fast reply ('do you ever sleep ?')
As you know telephonenumbers starts always with a country code. Like for the netherlands it is ('+31') and germany is ('+44'). The input must starts with '+31' or '+41' for example. Is this possible ? Or is there a help-file or FAQ wich explains how this string works, because i don't understand it.

Is this than the string : '^\+\31\44\d{10}$' ????

Regards and thanks, Theo






Quote Reply
Re: Validate Records In reply to
You may want to check out this recent thread started by HOBO

validate input ?
http://gossamer-threads.com/p/95601

I think you may be wanting to accomplish the same thing as HOBO. Although he was not including the "+" sign.

Hope this helps


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Validate Records In reply to
Smile I usually go to bed when most folks are getting up and sleep until about noon.

Oh, yes it's certainly possible. The expression will just be a little longer.

If your numbers have to start with +31 or +44, you would use

^\+31\d{8}$|^\+44\d{8}$

Regular expressions can be very complicated. I'm just really beginning to be able to understand them myself. There is a whole book on them. But I can explain the one above.

^ means "begins with"

+31 is one of the beginnings of your valid input. The / before the + is required because a + has some other meanings in regular expressions. This tells the script to look for the character and not to interpret it.

\d means "digits" -- or numbers.

{8} means that there has to be 8 of them. You have 10 numbers in your valid input, but you are already using two of them with your 31, so there must be 8 more.

$ means "ends with" so it won't accept anything that has more numbers or any letters or other characters after the 8 digits.

| means "or"

So, if I put the whole thing together, it means:

Begins with "+31" followed by exactly eight digits or begins with "+44" followed by exactly eight digits.

If you have other possiblities, you can just add them on to the end, separated by a |. For example, if you wanted to allow phone numbers that started with "+41" you would add

|^\+41\d{8}$

You can make it as long as you need to.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Records In reply to
Oke, Thanks a lot

Quote Reply
Re: Validate Records In reply to
Dear JPDeni
('hopely') One last question about this subject. You said exactly 8 digits, when i use the following |^\+31\d{14}$ is it possible to add less digitis then 14 because sometimes phonenumbers are tailer dan 8 digits

Quote Reply
Re: Validate Records In reply to
No, that won't work.

You can use \d{8,14}, though. That means "at least 8 but no more than 14 digits."


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Records In reply to
Thx for you reply
And other question about this subject. After a country like '+31' is not allowed to use a zero (it is the first number from the area code). Is it possible to check for this ?

If you dial the number from the netherlands use must the zero of the area code. If you dial the phonenumber from an other country you never use the 0 (zero)

example number: +31 30 1234567

+31 = netherlands (country code)

030 = area code (if dial the phonenumber from an other country you never use the 0 (zero)

1234567 = phonenumber



Quote Reply
Re: Validate Records In reply to
So when is a 0 okay and when isn't okay?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Records In reply to
after the '+31' it is not allowed to fill in a zero

+31301234567 is allowed
+310301234567 is not allowed

Quote Reply
Re: Validate Records In reply to
Maybe I can give you a general rule.

If you want the 0 to be "legal," use what I gave you before.

If you don't, use

^+##[1-9]\d{7,13}$

where ## is the two-digit prefix.

So, if you don't want a 0 when the prefix is "41" use

^+41[1-9]\d{7,13}$



JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Validate Records In reply to
It's almost working now. But we mean that only the first digit after the prefix may not be a zero. The following digits maybe zero's (with a minimum of 9 and a maximum of 12). We tried to fix it our self. Like this

^\+1[1-9]\d{1}[0-9]\d{9,12}$|^\+441[1-9]\d{1}[0-9]\d{9,12}$

Somethings strange happens now because with this \d{9,12}$
(the minimum of 9 digits and maximum 12 digitis after the prefix) But the minimum is now 12 digits and maximum is 15 digits. I don't understand this. Has it something to do with the prefix (sometimes it's 1 digit and other times it's 3 digits without the +)

Quote Reply
Re: Validate Records In reply to
I'm completely confused. I need you to tell me what is an acceptable entry into the field. If there are several acceptable patterns, list each one of them. Then I'll give you the regular expression needed.

JPD
http://www.jpdeni.com/dbman/