Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Field must be a number in create_account.php Help.


fasiso

Recommended Posts

Dear Friends

 

I need that the telephone field only alow numbers in create_account.php? How can I get it?

 

Thanks in advance.

 

Try this: find the following lines in create_account.php

 

	if (strlen($telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
  $error = true;

  $messageStack->add('create_account', ENTRY_TELEPHONE_NUMBER_ERROR);
}

 

After them, add:

 

	if (!preg_match('/^[\d\s]+$/',$telephone)){
  $error = true;

  $messageStack->add('create_account', ENTRY_TELEPHONE_NOT_NUMBER);
}

 

Then edit catalog/includes/languages/english.php, and add the line

 

define('ENTRY_TELEPHONE_NOT_NUMBER', 'Your Telephone Number must contain only numbers');

 

Add something equivalent to your other language files if needed.

 

Note that this will allow both numbers and spaces - if you want numbers only, just get rid of the "\s"

Link to comment
Share on other sites

  • 1 month later...

Hi!

 

This is just the thing I need. Problem is that I allow my customers to leave the phonefield blank, but this code forces the phonenumber to be filled in. How can I alter this code so that it doesnt give a errormessage if the field is left blank?

 

if (!preg_match('/^[\d\s]+$/',$telephone)){

$error = true;

 

$messageStack->add('create_account', ENTRY_TELEPHONE_NOT_NUMBER);

}

 

Greatful for help / Zuncan

So what?! Who care in a hundred years anyway?

Link to comment
Share on other sites

Hi!

 

This is just the thing I need. Problem is that I allow my customers to leave the phonefield blank, but this code forces the phonenumber to be filled in. How can I alter this code so that it doesnt give a errormessage if the field is left blank?

 

if (!preg_match('/^[\d\s]+$/',$telephone)){

$error = true;

 

$messageStack->add('create_account', ENTRY_TELEPHONE_NOT_NUMBER);

}

 

Greatful for help / Zuncan

 

 

Hi Zuncan,

 

try this

 

if (!preg_match('/^[\d\s]+$/',$telephone)){

if ($telephone != ''){

 

$error = true;

$messageStack->add('create_account', ENTRY_TELEPHONE_NOT_NUMBER);

}

 

}

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...