Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-04-2004, 10:46 AM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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!
Reply With Quote
  #2  
Old 08-04-2004, 11:26 AM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 08-04-2004, 11:31 AM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 08-04-2004, 11:49 AM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:21 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06318 seconds
  • Memory Usage 2,186KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete