Hi everybody...
I want to enter values to db like the following,,,
Format is like this (810605-14-6356)
This is the rite format, No a to z letters...
6 digits then - then 2 digits then - then 4 digits. -
dbConnect('db');
-
-
$ic = $_POST['icnumber'];
-
-
if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) {
-
//$ic is valid
-
error ('IC Number is not in right format.\\n'.
-
'Please enter IC Number agian.');
-
}
-
-
if ($ic==''
-
or $_POST['cicnumber']=='' ) {
-
error ('One or more required fields were left blank.\\n'.
-
'Please fill them in and try again.');
-
}
-
// this makes sure both passwords entered match
-
if ($ic != $_POST['cicnumber']) {
-
error ('Your IC Numbers not matched.\\n'.
-
'Please try again.');
-
}
-
-
// Check for existing user with the ic number
-
$sql = "SELECT COUNT(*) FROM m_users WHERE icnumber = $ic ";
-
$result = mysql_query($sql);
-
if (!$result) {
-
error('A database error occurred in processing your '.
-
'submission.\\nIf this error persists, please '.
-
'contact you@example.com.');
-
}
-
-
if (mysql_result($result,0,0)>0) {
-
error('A user already exists with your chosen IC Number.\\n'.
-
'Please try your own IC Number.');
-
}
-
-
-
$random = rand(1000000,9999999990);
-
-
-
$sql = "INSERT INTO m_users SET
-
icnumber = ('$ic'),
-
acccode = ('$random'),
-
actdate = curdate(),
-
expdate = DATE_ADD(curdate(), INTERVAL 1 month);
-
";
-
if (!mysql_query($sql))
-
error('A database error occurred in processing your '.
-
'submission.\\nIf this error persists, please '.
-
'contact admin@straight-a.com.my .\\n' . mysql_error());
-
-
?>
-
I make this code for it,, but its not working can anyone help me... -
$ic = $_POST['icnumber'];
-
-
if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) {
-
//$ic is valid
-
error ('IC Number is not in right format.\\n'.
-
'Please enter IC Number agian.');
-
}
-
Thanks in advance.
8 1912
Have you thought about creating three different fields in your MySQL table then in regards to the form separate it with three different fields. This way it will be able to read all the numbers simply without complicated code.
Special chars, when taken literally, must be escaped. You must escape the hyphens in your pattern with a backslash. Like - [0-9]{6}\-[0-9]{2}\-[0-9]{4}
Ronald :cool:
Thanks Ronald the problem is not solved with that.
i dont know why....
Plz help me out of this prob.
Thanks...
I did not show the full expression, just a sample of using literals. Here is the full test[php]if (preg_match('^\d{6}\-\d{2}\-\d{4}$^', $test)) {
echo "Matched on $test<br />";
}
else {
echo "Failed match on $test<br />";
}[/php]
Ronald :cool:
Thanks Ronald For reply have a great 2007.
I am now far away From my PC.
i will test it later..
But u use \d except of [0-9] ,, it will work..
I dont want to echo if the icnumber format is correct but if
wrong then error(i have common.php in which i call error mag), not echo..
Thanks again for ur help..
It is just a working sample to show you how to test it.You can adapt it to your heart's delight.
Ronald :cool:
Thanks Ronald for help..
I will test this, if any problem i will post reply...
Thanks
Thanks Ronlad for ur help.
i make some changes in it.. and now it is working.. -
if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) {
-
-
}
-
else {
-
error('IC Number format is not Valid.\\n'.
-
'Please try again.');
-
}
-
Thanks again for ur kind work on this prob... Sign in to post your reply or Sign up for a free account.
Similar topics
by: Garp |
last post by:
Everyone,
I know there's no comp.databases.mysql group, but if there's the demand for
questions about phrasing queries and the like that aren't PHP related (and
there is - every other q. seems...
|
by: Jeroen |
last post by:
I am developing an asp.net website with windows
authentification and I want to check to which group the
user belongs. I know how to check for the user that has
logged in and to see if he belongs...
|
by: Jake |
last post by:
Hello,
I am developing an application and there is a specific area in which I
want a specific group of windows users to access only. The users belong to a
group called Security1. How can I test...
|
by: Rich |
last post by:
The procedure below checks if a character entered into a cell of a
datagridview is contained in a string array of valid characters for this
particular cell. It seems kludgy. I am asking what the...
|
by: JasonC |
last post by:
Hi,
First time posting here so please be gentle!
I wish to check a variable for a number of words that are in a array.
Not sure if this is the best way to do it, but this is what i have.
...
|
by: rote |
last post by:
My sceanrio is this on an asp.net 2.0 freamework.
I want to use any of the data controls e.g Gridview,DetailView etc..
But i want some buttons e.g update,edit save etc to be enable or disabled...
|
by: wswilson |
last post by:
In python, I could write:
a = 1
if a in :
do something...
In c (and many other languages):
|
by: marioliveira |
last post by:
I have a orm built with RSForms Pro in which there is a calendar. The form is about bookings for activities, some of which are not available every weekday. Is there a way of checking the date the...
|
by: doma23 |
last post by:
This thread was taken from a post in Nz function not working and refers to comments in post #4.
Yeah, I was thinking if you could share that API function you have, because I was searching for a...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |