phone regex with length validation in php

as per the specification phone number should be

Alhpa-Numeric, Space allowed, hypen allowed, bracket allowed, max length = 45 can be null as well.

below is what i made using my limited knowledge and examples but its giving

error : Compilation failed: nothing to repeat at offset 29

My PHONE regex =

define('PHONE','#([a-zA-Z0-9][\s\(\)\-])*{0,45}#i');

please guide what should i do to have all the above specification matched using regex. thanks

Answers


The regex won't match what you want, with ([a-zA-Z0-9][\s\(\)\-]) each number must be followed by a space, parentheses or hyphen. to fix that make [\s\(\)\-] optional:

([a-zA-Z0-9][\s\(\)\-]?)

and use preg_match.


Remove the *. The {0,45} defines the number of repeats allowed.


Need Your Help

Remove TinyMCE control and re-add

javascript html tinymce state

I have a js application that never reloads the page, so when navigating I need to remove TinyMCE controls entirely, and then I want to re-initialize when navigating to an area that needs it. I trie...

Order column by keyword

php sql order

I have a database filled with records and by using this MySQL-syntax:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.