0

I'm currently using the Contact Form 7 plugin, which is great and works perfectly, but what I'm now trying to achieve with it is some custom validation rules.
I found this extension: http://code-tricks.com/contact-form-7-custom-validation-in-wordpress/ that once added to functions.php adds a whole raft of extra validation rules.
For example:

$acceptNumbers = array('acceptNumber', 'acceptNumber1', 'acceptNumber2', 'acceptNumber3', 'acceptNumber4', 'acceptNumber5', 'acceptNumber6');

foreach($acceptNumbers as $acceptNumber){
    if($name == $acceptNumber) {
        $acceptNum = $_POST[$acceptNumber];

        if($acceptNum != '') {
            if(ctype_digit($acceptNum)) {
                $result['valid'] = true;
            } else {
                $result['valid'] = false;
                $result['reason'][$name] = 'Please Enter Only Numbers';
            }
        }
    }
}

Called in the short code like so: [text* acceptNumber] but what I want to validate is quite specific and I'm not sure how it'll be achieved. I'll have 1 text field, I want it to contain ONLY one word, anything more than one word won't be accepted, and this one word MUST begin with the letter s. I'm not even sure if this is at all achievable, any suggestions would be greatly appreciated!

closed as off-topic by birgire, Pieter Goosen, fuxia Jul 26 '14 at 9:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

Hope I did get it right:

<?php

function specialValidation($value) {
    $explode = explode(' ', $value);
    if(sizeof($explode) > 1) {
        echo 'ERROR: You have input more than one word.';
        return;
    }
    $mustBeS = substr($explode[0],0,1);
    if($mustBeS != 's' && $mustBeS != 'S') {
        echo 'ERROR: Your word must start with an "s" or "S".';
        return;
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.