vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Regex (https://vborg.vbsupport.ru/showthread.php?t=67985)

Colin F 08-04-2004 10:46 AM

Regex
 
Hi

I'm trying to get these stupid regular expressions to work on profile fields.

Could someone check these, I seem to have something wrong in them.

Postcode (4 Numbers, first 1-9, second, third and fourth 0-9)

/^[1-9][0-9]{3}$/

Telephone number In the format: 062/775 12 34 or 01/775 56 78

So that means: First digit: 0
second digit: 1-9
third digit (optional) 1-9
than a backslash: /
fourth digit: 1-9
fifth and sixth digit: 0-9
then a space:
seventh and eighth digit: 0-9
then a space:
ninth and tenth digit: 0-9

I have this:

/^[0]?[0-9]\/[1-9][0-9]{2}\s[0-9]{2}\s[0-9]{2}$/

Mobile Phone Number: In the format: 076/123 45 67

first digit: 0
second digit: 7
third digit: 6, 8 or 9
then a backslash: /
fourth digit: 1-9
fifth and sixth digit: 0-9
then a space:
seventh and eighth digit: 0-9
then a space:
ninth and tenth digit: 0-9

I have:

/^07[6-9]\/[1-9][0-9]{2}\s[0-9]{2}\s[0-9]{2}$/

Thanks for your time!

CarCdr 08-04-2004 11:26 AM

Postal code /^[1-9][0-9]{3}$/ looks right. Are you sure there is not leading or trailing whitespace? Since you are matching the entire field with ^$, you may want to deal with the whitespace by including \s* at the beginning and end.

Telephone number one does not match the english you provide. For example, you say "First digit: 0, second digit: 1-9, third digit (optional) 1-9", but your regular expression says starts with a search for optnal zero, 0-9, then a forward slash.

I think this matches your english (but I have including test for leading/trailing whitespace):
/^\s*0[1-9][1-9]?\/[1-9]\d{2}\s\d{2}\s\d{2}\s*$/

Note that I prefer \d to [0-9], so I used that.

CarCdr 08-04-2004 11:31 AM

Ooops, forgot the mobile telephone number one. This should work:

/^\s*07[689]\/[1-9]\d{2}\s\d{2}\s\d{2}\s*/

I did not read your expression in detail, just the english, but one thing I did notice was that you said "third digit: 6,8 or 9", but your test was for "[6-9]", which would include the digit 7.

Colin F 08-04-2004 11:49 AM

I assume that vBulletin trims the fields anyway, so I might as well put that \s there, you're right.

Unfortunatelly, when I sign up I still get an error message for the mobile number (I think it checks that one first and only echoes out that error...

Oh, and thanks anyway.

I left the 7 in there because I didn't feel like figuring out how to get rid of it :)


All times are GMT. The time now is 12:30 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01038 seconds
  • Memory Usage 1,715KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete