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 6251173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:33:54+00:00 2026-05-24T13:33:54+00:00

I have a php script which I need to validate several inputs with. Is

  • 0

I have a php script which I need to validate several inputs with.

Is there any reliable and very good regular expression to check against when it comes to telephone nr, name and email adress validation?

Could somebody please supply these as I am very novice in regexp?

What I want is for example:

Telephone Nr: all number allowed, must be atleast 6 numbers, max 12 numbers, ‘+’ sign allowed, space allowed, ‘-‘ sign allowed, as well as other things I haven’t thought about yet.

Name: No numbers allowed, only characters in both lower and uppercase. Also the three swedish chars ‘Å, Ä, Ö’ in both lower and uppercase, also space, ‘-‘ sign allowed, and all others I havent thought about.

Email: Email adress is pretty standard over the world, so I don’t know exactly what to ask for here, but you probably know what I want.

Thanks for all help

  • 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-24T13:33:57+00:00Added an answer on May 24, 2026 at 1:33 pm

    As Andrew White said, emails shouldn’t be validated [only] by regex, but you can check out this one:

    '/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i'
    

    it’s closest to the email address spec I’ve ever found (no tests have been found which it fails)… can’t remember where it’s from, will edit my answer as soon as I find it again

    [EDIT]

    Found it, definitely worth a read: http://fightingforalostcause.net/misc/2006/compare-email-regex.php

    [EDIT]

    This should do for the phone numbers:

    <?php
    
    function is_valid_phonenumber( $subject ) {
    
      // strip all valid chars
      $stripped = preg_replace( '{[0-9 +-]}', '', $subject );
    
      // check if there are remains, if yes: fail
      if( !empty( $stripped ) )
        return false;
    
      // get digit count by replacing everything except digits with nothing
      $digits = strlen( preg_replace( '{[^0-9]}', '', $subject ) );
    
      // invalid if less than 6 or more than 12 in length
      if( $digits < 6 || $digits > 12 )
        return false;
    
      // if nothing fails before this, we're good to go
      return true;
    
    }
    
    ?>
    

    Similar can be done for the names, but don’t forget the case-insensetive flag (i.e. '{pattern}i', there are also some good regex cheat sheets out there, for example this one from addedbytes.com: http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/

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

Sidebar

Related Questions

I have a php script which accesses a MSSQL2005 database, reads some data from
I have a PHP script which executes a shell command: $handle = popen('python last',
I have several independent executable Perl, PHP CLI scripts and C++ programs for which
I have a PHP script which creates and listens on a port for connections
I have a php script which needs to connect to a database. The credentials
I have a PHP script which calls methods from a class I have written.
I'm implementing a PHP script which will need some caching capabilities. I'm trying to
I need a PHP script which takes a URL of a web page and
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via

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.