473,320 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Allowing a DASH to pass as numeric

moishy
104 100+
I want that certain fields in my form must be numeric.

I'm using the "if_numeric" code for that.

But if I submit a form with a phone number that contanes a dash, It will not be accepted.

Example:

Phone: 1516-678-9010

Will not be accepted.

However, only such a number will be accepted:

Phone: 15166789010


So, how to I add a "DASH" to the "Whitelist"?
Oct 11 '06 #1
2 1649
ronverdonk
4,258 Expert 4TB
The following is a little snippet that, after removing the blanks and the dashes, checks if the input field contains 9 to 14 digits only. You could use that to check your telephone no, allowing people to have blanks or dashes inside.
[php]
$tests = array( "314-5565-400",
"800-555-4400",
"(314)555-4000",
"3146784000",
"555",
"5342 875 6478",
"1234-123-12345"
);
foreach ($tests as $test) {
if (preg_match('^\d{9,14}$^', str_replace(array(" ","-"), "", $test))) {
echo "Matched on $test<br />";
}
else {
echo "Failed match on $test<br />";
}
}
?>
[/php]

Ronald :cool:
Oct 13 '06 #2
The ascii character of '-' has to be taken and check the ascii value entered using Charcodeat function.
Oct 13 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Brian | last post by:
I am trying to pass a null value into a stored procedure so that it can save the data. I am using Microsoft's SQLHelper dll to do this. My example code is below. How do I pass in a null value...
7
by: Harlan Messinger | last post by:
How far back in their version history did Netscape and Internet Explorer support — and – codes for em and en dashes in text? In ALT attributes? In TITLE tags? I notice that Netscape 4.7 and 6...
8
by: Danny | last post by:
I've read the recent post about not breaking at hyphens in HTML documents. I *want* breaking to occur at hyphens. (for 'hyphen' read 'minus sign') IE6 and Opera7.54 both break phrases such as...
1
by: mats.broberg | last post by:
Dear all, I'm having a scientific text translated into the majority of western and eastern European languages* and have provided a small leaflet with typesetting rules for the translators. Some...
5
by: Reny | last post by:
can any one tell how can i restrict my user to type just numeric character in the textbox.I am using VS.NET 2003 (VB.NET)
19
by: Carson | last post by:
Is it possible to remove the dashes in a social security number using sprintf? If so what would the syntax look like? If sprintf won't do this is there a C function that will?
5
by: DotNetNewbie | last post by:
Hi, I want to parse a string, ONLY allowing alphanumeric characters and also the underscore '_' and dash '-' characters. Anything else in the string should be removed. I think my regex is...
0
by: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= | last post by:
"C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 149, in Here it complains that it deals with the character U+2013, which is "EN DASH"; it complains that the encoding called "latin-1"...
15
by: ajd335 | last post by:
Hi all, I have one webpage in which people can order books online. i have one array - book , in which i have stored all different types of books. Now, I dont want the user to order any garbage (...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.