Hi guys,
I want to validate a string to make sure it contains only digits.
0001 = true
6669 = true
00a0 = false
6.665 = false
What's the best way to go about doing that ?
Take care,
Cyrus 6 12576
Cyrus D. wrote: Hi guys,
I want to validate a string to make sure it contains only digits.
0001 = true 6669 = true 00a0 = false 6.665 = false
What's the best way to go about doing that ?
Lots of ways to do it.
This is one way: preg_match('/^\d{4,4}$/', $var)
/Bent
Cyrus D. wrote: Hi guys,
I want to validate a string to make sure it contains only digits.
0001 = true 6669 = true 00a0 = false 6.665 = false
What's the best way to go about doing that ?
Take care, Cyrus
preg_match('`^[0-9]+$`',$string);
returns TRUE if *only* digits are in the string, no matter what length
it is.
--
Justin Koivisto - sp**@koivi.com http://www.koivi.com
Cyrus D. wrote: Hi guys,
I want to validate a string to make sure it contains only digits.
0001 = true 6669 = true 00a0 = false 6.665 = false
What's the best way to go about doing that ?
An alternative suggestion without regexps:
is_numeric($str ing) && strval(floor(in tval($string))) == $string
Checks if $string is numeric; and then removes possible decimal places and
compares that to the original (to make sure there are no points).
--
Markus
On Wed, 20 Oct 2004, Markus Ernst wrote: Cyrus D. wrote: I want to validate a string to make sure it contains only digits.
An alternative suggestion without regexps:
is_numeric($str ing) && strval(floor(in tval($string))) == $string
Checks if $string is numeric; and then removes possible decimal places and compares that to the original (to make sure there are no points).
Technically this will also allow strings which begin with "-" or "+", and
those which contain a "." followed solely by zeros. This might be what is
required, though.
--
Matt
Matt Raines wrote: On Wed, 20 Oct 2004, Markus Ernst wrote:
Cyrus D. wrote: I want to validate a string to make sure it contains only digits.
An alternative suggestion without regexps:
is_numeric($str ing) && strval(floor(in tval($string))) == $string
Checks if $string is numeric; and then removes possible decimal places and compares that to the original (to make sure there are no points).
Technically this will also allow strings which begin with "-" or "+", and those which contain a "." followed solely by zeros. This might be what is required, though.
Well it is rather a mistake in my thinking... a corrected version:
is_numeric($str ing) && number_format(a bs($string), 0, "", "") === $string
--
Markus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: google |
last post by:
I'm trying to implement something that would speed up data entry. I'd
like to be able to take a string, and increment ONLY the right-most
numerical characters by one. The type structure of the data that is in
this field can vary. It's a list of mechanical equipment, and how it
is designated varies based on how the customer has them labeled. For
example, a list of their equipment might look like:
CH-1
CH-2
CH-3
|
by: Henke |
last post by:
Hi!
Is there a simple way to check if a string entered in a text box is a valid
integer?
Thanks in advance!
/Henke
|
by: zjut |
last post by:
I need to implement the method : round(String name, int index)
The given string maybe the every type of float type, ( the msdn given the
regax is that :
integral-digits]exponential-digits])
and the index is the location after "." in name.
First, i should check the given name is a valid float-point, and then,
to check the number in name in index locaion is > 0 or not?
eg:
|
by: nescio |
last post by:
hello,
i must check if the value of a text field is a number (they have to fill in
a number between 7 and 10 digits),
so: 1234567 is allowed
and 123456789999 is not allowed;
also, there are no other characteres allowed:
wrong: 12345ABV
wrong: 12#$as1123
|
by: karthi |
last post by:
hi,
I need user defined function that converts string to float in c.
since the library function atof and strtod occupies large space in
my processor memory I can't use it in my code.
regards,
Karthi
| |
by: Anoop |
last post by:
Hi All
I am getting two different outputs when i do an operation using
string.digits and test.isdigit(). Is there any difference between the
two. I have given the sample program and the output
Thanks for ur inputs
Anoop
|
by: PythonistL |
last post by:
I am a newbie with Javascript and would like to check if a text
provided by a users , during filling in an input field , has digits
only.
Any idea?
Thank you
L
|
by: Kris |
last post by:
I need to create a valid mod10 or luhn number that can be attached to
an invoice, I have found several examples showing how to validate a
credit card number or validate a number using mod10/luhn.
Example:
invoice number = 700123
invoice check number 700123(checknumber)
that check number should make the entire invoice number able to
validate using mod10/luhn
|
by: erictheone |
last post by:
so here is my code. My getlines for the strings keyword and phrase at lines 44 and 79 respectively don't work. Please help!!!
#include <cstdlib>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
string removeAllWhite( string eric)
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |