How - Not allow space as first two characters in field

saf01 12 Nov, 2008
Hi. Ive designed a simple css form and pretty happy with it, validated it and all is working well. When I add one or more spaces only in the required field (eg my address field), the Mootools validation allows this validation to go through. If its empty it shows, as normal, this is required field. My question is: How can I stop allow spaces as the first two characters - spaces only allowed after the first two characters being text or number? Can this be done?

Please advise. Thanks.
Max_admin 12 Nov, 2008
Hi saf01,

may be you will need to use your own JS code to do this special validation!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
melidj 09 Sep, 2010
Max,
I am having the same issue. Do you have an example of code to alleviate this issue? I'm not super technical, but I can edit the code if you can give me an idea of where to begin.
Thank you,
Melidj
GreyHead 10 Sep, 2010
Hi Melidj,

You can do this with a custom validation using a regular expression. There are a few examples here. However it might be easier to add a little snippet of code in the server-side validation box.
<?php
$var_name = JRequest::getString('var_name', '', 'post');
if ( substr($var_name, 0, 2) == '  ' ) {
    return "Please don't put spaces at the beginning";
}
?>
NB Not tested and may need debugging.

Bob
melidj 10 Sep, 2010
Bob,
Not to seem ignorant - but I am somewhat - here is the code for the input box:

<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 300px;"><font color="red">*</font>Bid Intent for (enter project title here <font color="red">(required)</font>):</label>
<input class="cf_inputbox required validate-alpha" maxlength="500" size="30" title="" id="text_12" name="text_12" type="text" />

Where would I insert the code (Thank you!) you provided?

Please advise.

Thank you,
Melidj
GreyHead 12 Sep, 2010
Hi melidj,

The code goes in the Server-side validation box on the Validation tab in the Form Editor. You'll need to replace 'var_name' (several times) with 'text_12'.

Bob
This topic is locked and no more replies can be posted.