Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 669271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:07:59+00:00 2026-05-14T00:07:59+00:00

I was wondering if the codes below are the correct way to check for

  • 0

I was wondering if the codes below are the correct way to check for a street address, email address, password, city and url using preg_match using regular expressions?

And if not how should I fix the preg_match code?

 preg_match ('/^[A-Z0-9 \'.-]{1,255}$/i', $trimmed['address']) //street address
 preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'] //email address
 preg_match ('/^\w{4,20}$/', $trimmed['password']) //password
 preg_match ('/^[A-Z \'.-]{1,255}$/i', $trimmed['city']) //city
 preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i", $trimmed['url']) //url
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:07:59+00:00Added an answer on May 14, 2026 at 12:07 am

    Your street address: ^[A-Z0-9 \'.-]{1,255}$

    • you need not escape the single quote.
    • since you have a dot in the char
      class, it will allow all char (except
      newline). So effective your regex becomes ^.{1,255}$
    • you are allowing it to be of min
      length of 1 and max of length 255. I
      would suggest you to increase the min
      length to something more than 1.

    Your email regex: ^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$

    • again you are having . in the char
      class. fix that.

    Your password regex: ^\w{4,20}$

    • allows for a passwd of length 4 to 20
      and can contain only alphabets(upper
      and lower), digits and underscore. I would suggest you to allow
      special char too..to make your
      password stronger.

    Your city regex: ^[A-Z \'.-]{1,255}$

    • has . in char class
    • allows min length of 1 (if you want
      to allow cities of 1 char length this
      is fine).

    EDIT:

    Since you are very new to regex, spend some time on Regular-Expressions.info

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the correct way to use signal handlers? I saw the codes below
I'm just wondering on how would you check java codes like System.Out.println(hi); it should
I was just wondering about the correct way to return a reader from a
Just wondering about this code below... when I turn off my internet connection and
I have the code below. I'm wondering that does the self.value and _value have
I was wondering if anyone had an idea as to why the code below
I was wondering how can I allow NULL values in the following code below
Ok, so I have the code below (Objective-C FYI) and I was wondering if
I'm wondering about the .childNodes property, I have the code below, and for some
I was wondering if anyone knows how to get formatted or styled codes from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.