Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9105905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:12:46+00:00 2026-06-17T02:12:46+00:00

I have a Post model which has the following validation rules: public $validate =

  • 0

I have a Post model which has the following validation rules:

public $validate = array(
    'title' => array(
        'between' => array(
            'rule' => array('between', 1, 60),
            'message' => 'Between 1 and 60 characters in length'
        ),
        'format' => array(
            'rule' => array('custom', '~[a-zA-Z0-9\s-]~'),
            'message' => 'Alphanumeric characters, spaces and dashes (-) only'
        )
    ),
    'body' => array(
        'between' => array(
            'rule' => array('between', 1, 65535),
            'message' => 'Between 1 and 65535 characters in length'
        )
    ),
    'slug' => array(
        'between' => array(
            'rule' => array('between', 1, 60),
            'message' => 'Between 1 and 60 characters in length'
        ),
        'format' => array(
            'rule' => array('custom', '~[a-zA-Z0-9-]~'),
            'message' => 'Alphanumeric characters and dashes (-) only'
        )
    )
);

I also have a view to insert a new post which looks like this:

<?php $this->Html->script('add-post', array('inline' => false)); ?>

<h1>Add post</h1>

<?php echo $this->Form->create('Post'); ?>
<?php echo $this->Form->input('title'); ?>
<?php echo $this->Form->input('body'); ?>
<?php echo $this->Form->input('slug'); ?>
<?php echo $this->Form->end('Publish'); ?>

Now, when I submit the form with the title being something like blog post title £$&£$^£$ it goes through and gets inserted, despite the regex not matching the symbols in that title. This happens on all fields where regex is used to check the format.

However, if I try to submit a post which doesn’t pass the between rule (like a title over 60 characters) it successfully throws up a validation error.

What could be going wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:12:47+00:00Added an answer on June 17, 2026 at 2:12 am

    Your regex pattern is only checking that at least one of those characters is found anywhere in the string. So if you were to post just £$&£$^£$ by itself it would fail because the valid characters aren’t found anywhere in that string. You should replace the rule with this:

    ~^[a-zA-Z0-9\s-]+$~
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Post model which has many ratings and I would like to
Assuming i have a post model with created_at, title, and id. How can i
I have a Topic model and a Post model. A Topic has many Posts,
In this simplified scenario, I have a model called Post Each post has a
I have the following model: public class Product { public int Id { get;
I have created a following model public class myModel { public int ID; public
I have a Post model and a View model (which logs the view of
I have coded a single threaded client server model which does following: Server loops
Complete beginner to Rails here: In Rails: I have a Model Post, which hasmany
I have an application architecture which has following layers (or c# projects). web front

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.