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 4 of 4
  1. #1
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    925
    Thanks
    76
    Thanked 29 Times in 29 Posts

    Using ctype functions

    Hello,

    I am starting to validate my form post data and wondered if there is anyway I can get around using the ctype_alpha() function in allowing a space to be entered in that given string?

    I need to be able to let the user enter a space in the 'name' field in-case they try entering their surname.

    Do I need to manually search, do something like:
    PHP Code:
    $characters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";

    //search each position in the input string, if at any time it doesn't contain 
    //something in the above string, do error. if it does always contain 
    //a value from the above string, we know its ok? 
    Thank you for your thoughts.

    Kind regards,

    LC.
    Last edited by LearningCoder; 11-12-2012 at 03:05 AM.

  • #2
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    I think using a regular expression would be what you want. Perhaps preg_match() is the right function, although I'm not certain of the exact syntax. Maybe it would be like this:

    PHP Code:


     
    if(preg_match("^([a-z ])*$"$input ) { /* $input contains only letters and spaces. */ 
    You can read more here. It would also be good for someone else to check that syntax I used, I'm not too confident.

  • #3
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    925
    Thanks
    76
    Thanked 29 Times in 29 Posts
    I thought about regular expressions you know but when I was studying JavaScript a few years back, I kinda got stumped on that subject

    I'll give it another read though if it will make life easier.

    Thank you for your reply.

    Kind regards,

    LC.

  • #4
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    925
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Just been looking through some regular expression tutorials and it's just far too complicated for me to understand.

    Also your code doesn't work and I've been trying to modify it, but again I haven't got a clue what I'm doing.

    I'll stick to manually checking the input because I don't just want to copy some code I don't understand even if it does what I want. I want to really know my code well and be able to change it.

    Thanks anyway,

    Regards,

    LC.


  •  

    Posting Permissions

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