How to remove hyphens in phone field

Discussion in 'Templates customization' started by jennifer6, Nov 4, 2010.

  1. jennifer6

    jennifer6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    17
    Hi,
    I could use some help. How do I remove the hyphens or other special characters in the phone field for my database? THANKS so much! Jenn
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    this can't be done as simple SQL query, but can be done in php:
    PHP:
    <?
    include 
    "/full/path/to/amember/config.inc.php";
    foreach(
    $db->users_find_by_string('%''login') as $u){
      
    $u['phone'] = preg_replace('/\D/''',$u['phone']);
      
    $db->update_user($u['member_id'], $u);
    }
     
    ?>
    Please backup database before doing this.
  3. jennifer6

    jennifer6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    17
    great but another q ...

    great thanks alex. it worked.
    is there a way to add this code as a part of the template or before the form is submitted (instead of running script separately every day)?
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Sure, in signup template you can use jQuery validator plugin to validate that field.
    Add this class for phone field:
    Code:
    class="required number"
    

Share This Page