1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Check if field only contains alphanumerics (no spaces or special chars)

Discussion in 'XenForo Development Discussions' started by account8226, Jan 3, 2013.

  1. account8226

    account8226 Guest


    I am trying to validate one of my fields. In my datawritter I am calling a validating function, that call a method 'validate' in my model.

    if (preg_match('/[^a-zA-Z0-9_]/'$username)) return false;
    Why is that not working ? It's always returning false...
  2. account8226

    account8226 Guest

    Solved it, was just passing out the wrong variable ;) This preg match function works.
  3. Jaxel

    Jaxel Well-Known Member

    I recommend using # instead of /.
    preg_match('#[^\w]#', $username)

Share This Page