Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please help: function to prevent numbers and @ signs in text field

    I have this code on the submit.php file, but I am getting a syntax error.

    function check_fields()
    {

    $HTTP_POST_VARS['brief']=preg_replace("/0,1,2,3,4,5,6,7,8,9/", /www/",/@/",""$HTTP_POST_VARS['brief']);

    }

    Please help. I need to delete or remove phone numbers, web address and email from the brief field. Many thanks
    Last edited by mark-new; 03-03-2012 at 10:32 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts

  • #3
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have this code on the submit.php file, but I am getting a syntax error.

    function check_fields()
    {

    $HTTP_POST_VARS['brief']=preg_replace("/0,1,2,3,4,5,6,7,8,9/", /www/",/@/",""$HTTP_POST_VARS['brief']);

    }

    Please help. I need to delete or remove phone numbers, web address and email from the brief field. Many thanks

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    As a start; HTTP_POST_VARS is deprecated, you should be using $_POST.

    Secondly what if someone uses 'shorthand' and writes "I was @ the show"? Or "There were 3 of us"?

    three params $pattern, $replacement, $string - Does your example have three?
    Last edited by litebearer; 03-03-2012 at 10:56 PM.

  • #5
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by litebearer View Post
    As a start; HTTP_POST_VARS is deprecated, you should be using $_POST.

    Secondly what if someone uses 'shorthand' and writes "I was @ the show"? Or "There were 3 of us"?

    three params $pattern, $replacement, $string - Does your example have three?
    Thank you for your response. I am new to this, I just want to apply this rule. what is the correct code format . I already have a field for phone numbers and emails, I just do not want it in description field. Thanks

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    For email addresses you could extract everything on either side of the @ out to the nearest word boundary ( /\b.+?@.+?\b/ ) and then use if(filter_var($email, FILTER_VALIDATE_EMAIL)) to determine if it is an email address and therefore needs to be removed. You should be able to do that test in about a dozen lines of code.

    Unfortunately while email addresses have a standard format, phone numbers so not and since they can contain spaces and even letters there is not actuall boundary that you can easily use to perform a similar test for phone numbers. The amount of code needed to actually identify a phone number in a free format field is huge. I actually looked into that situation about 20 years ago where I needed to extract phone numbers from a free format field where most records did contain a phone number. With the several hundred lines of code that I settled on using for trying to identify phone numbers I still had about 5% of the results where dates or other numbers had been matched instead of actual phone numbers.
    Last edited by felgall; 03-03-2012 at 11:29 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    For email addresses you could extract everything on either side of the @ out to the nearest word boundary ( /\b.+?@.+?\b/ ) and then use if(filter_var($email, FILTER_VALIDATE_EMAIL)) to determine if it is an email address and therefore needs to be removed. You should be able to do that test in about a dozen lines of code.

    Unfortunately while email addresses have a standard format, phone numbers so not and since they can contain spaces and even letters there is not actuall boundary that you can easily use to perform a similar test for phone numbers. The amount of code needed to actually identify a phone number in a free format field is huge. I actually looked into that situation about 20 years ago where I needed to extract phone numbers from a free format field where most records did contain a phone number. With the several hundred lines of code that I settled on using for trying to identify phone numbers I still had about 5% of the results where dates or other numbers had been matched instead of actual phone numbers.
    Thanks, I only wanted to remove numeric numbers not necessarily phone numbers. ok let say I do not want to filter the numeric numbers and want remove or replace the @signs and web url how would the correct syntax for this code be implemented?

    function check_fields()
    {

    $HTTP_POST_VARS['brief']=preg_replace("/0,1,2,3,4,5,6,7,8,9/", /www/",/@/",""$HTTP_POST_VARS['brief']);

    }

    Thanks for your help

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    $brief = preg_replace("/\d|@/","",$_POST['brief']);

    will get rid of all the numbers and @ symbols in the text. (note that $HTTP_POST_VARS is a PHP 3 command that was replaced by $_POST in PHP 4).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    $brief = preg_replace("/\d|@/","",$_POST['brief']);

    will get rid of all the numbers and @ symbols in the text. (note that $HTTP_POST_VARS is a PHP 3 command that was replaced by $_POST in PHP 4).
    Many thanks it works, my application is using PHP3. Many thanks again

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Why are you using PHP 3 - PHP 4 is long dead and full of security holes - PHP 3 is positively pre-historic and should never be even remotely considered unless you are living in the stone age or earlier.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I do not know if this make sense, I am using jooomla 1.5 with php 5.2.17 but the php file I am working on uses $HTTP_POST_VARS in the coding.

  • #12
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by mark-new View Post
    I do not know if this make sense, I am using jooomla 1.5 with php 5.2.17 but the php file I am working on uses $HTTP_POST_VARS in the coding.
    Why are you running such an antiquated version of Joomla? The latest security patch is 2.5.1.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •