php


Regular expression for phone number in codeigniter


I am using codeigniter and I want to check user input with regular expression for phone number. My pattern is [+]zero or one and [0-9] number.
Following format,
+959250142935
09250142935
This is my pattern - /\+?[0-9]$/
This does not work as I expected.
You can use the following pattern to check for valid phone number. There is a additional {5,} to set a minimum length of the phone number (in this case 5), so the phone number can't be a single number:
^[\+]{0,1}[0-9]{5,}$ or ^[\+]{0,1}\d{5,}$
You can use this pattern directly on the <input>:
<input pattern="^[\+]{0,1}[0-9]{5,}$" type="text"/>
<input pattern="^[\+]{0,1}\d{5,}$" type="text"/>
Try with this regex
/^(\+|0|1)\d+$/
If the number must be certaing length
/^(\+|0|1)\d{10}$/

Related Links

Using folders to select pages
Which characters should I strip from the user's password, before inserting into database?
PHP built-in SOAP passing parameters
filename not showing, but img gets uploaded? [closed]
How to do an advanced search in php?
SQL/PHP - INSERT statement using PDO and data inside the table appears as 'Resource ID #'. How can I get it to store the correct string?
Array isn't fetching all data because of if statement
Laravel Framework: syntax error, unexpected 'function' (T_FUNCTION) [closed]
SQL Update Command updates all values in a column
Send the body message with the css code using PHPMailer does not work
Facebook API integration error through php
Xpath Date Comparison using PHP
affected_rows() in codeigniter
Get max of each unique key in multidimensional array [closed]
Traversing into dates and getting the lowest day difference between two dates
how to execute select query in Code igniter [closed]

Categories

HOME
cocoapods
office365
android-espresso
mod-rewrite
tomcat
functional-programming
writefile
swi-prolog
devexpress
semantic-web
cryptography
gentelella
angular2-template
sympy
roku
azure-graph-api
locationmanager
alljoyn
nsstring
amazon-elb
squirrel-sql
dhcp
sql-injection
squid
bnf
google-sites
jitsi
pe
weex
bsd
maven-surefire-plugin
connection-refused
managed-c++
beego
amazon-iam
infopath2010
argv
snap-framework
series
osx-lion
cloveretl
restful-architecture
java-stream
polyml
wdk
stackpanel
twilio-php
linq.js
praat
uipickerview
newtons-method
hypothesis-test
google-prediction
ol3-google-maps
password-hash
sharpdx
redisson
line-intersection
zend-server
emf-compare
email-injection
qtextedit
elastic4s
ftp-client
callouts
piping
adp
vaadin4spring
odesk
miniconda
phpredis
whitespace-language
signed
hp-idol-ondemand
quantify
communicate
rpg
ivalueconverter
oxygene
cpu-time
roxy-fileman
pbkdf2
progress-db
mousemotionlistener
stty
django-facebook
xs
proc-open
gprof
ip-geolocation
workflow-manager-1.x
telerik-ajax
system-information
dropshadow
boost-foreach
radscheduler
jmenu
downgrade
resharper-5.1
odac
aspbutton
google-translator-toolkit
wmd-editor
.net-client-profile
iphone-sdk-3.1.3
code-camp

Resources

Encrypt Message