-
1. Re: Spry Validation on Text field
BenPleysier Dec 17, 2012 4:50 PM (in response to winrol)First create a little JavaScript function that contains a regular expression ( see here http://regexlib.com/?AspxAutoDetectCookieSupport=1) to validate that there are no spaces
<script>
function ValidateNoSpaces(value) {
return /^[a-zA-Z]+$/.test(value)
}
</script>
Then apply a custom validation to the constructor
var sprytextfield6 = new Spry.Widget.ValidationTextField("spryRegisterLastname", "custom", {validation:ValidateNoSpaces, validateOn:["blur", "change"]});
-
2. Re: Spry Validation on Text field
winrol Dec 17, 2012 10:04 PM (in response to BenPleysier)Thanks Gramps, that worked, but...
I was thinking and what if someone had a 2 part last name, ie Van Houte? I get a error when I go through my form. So I though if I added a min char length to the script. Like so:
What I want is to have the script assign a temp val then check the val to see if less than 5 AND there are spaces then error else pass no error. I have tested this with adding alert messages to see if I was getting what I want. I was except when I get down to the if(/^[a-zA-Z]... part. How would I write the validation for the checking the variable for spaces?
<script>
function ValidateNoSpaces(value) {
var tempstr = value.length;
if(tempstr < "5") {
if ( /^[a-zA-Z]+$/.test(tempstr)="false") {
return /^[a-zA-Z]+$/.test(value);
}
}
}
</script>
Also, is it possible to run the spry validation after as I don't get any notification of what is wrong. The text box just changes to a red color.
Thanks Winrol
-
3. Re: Spry Validation on Text field
BenPleysier Dec 17, 2012 10:42 PM (in response to winrol)It is best to use a regular expression. Think of a name like 'de la Rue'. Have a look at the last example here http://regexlib.com/Search.aspx?k=surname&c=-1&m=-1&ps=20
for the second part of your question, add the highlighted line
<span id="spryRegisterLastname">
<label for="text1"></label>
<input type="text" name="text1" id="text1">
<span class="textfieldRequiredMsg">A value is required.</span>
<span class="textfieldInvalidFormatMsg">Not the required format.</span>
</span>
-
4. Re: Spry Validation on Text field
winrol Dec 18, 2012 10:37 AM (in response to BenPleysier)Thanks Gramps that works awesome.
-
5. Re: Spry Validation on Text field
winrol Dec 19, 2012 2:52 PM (in response to BenPleysier)Hey Gramps, after playing with this for a bit I noticed that everthing works fine but when I add a space anywhere inside the field I get and Invalid error. I want to allow someone to enter a space then another word I just don't want client entering spaces to complete the field.
Thanks Winrol