View Full Version : Validating content of text field

14 Nov 2011, 4:03 AM
Hi all,

I am just learning ExtJS for my work requirement(older version 3.4). I was trying to validate a text field also I want textfield not to contain any blank spaces. My text field is not inside a form.

I tried following code just to check validation against hard coded string

items: [ {
attributeName: 'jobTitle',
maxLength: 100,
xtype: 'textfield',
validator: function(value)
if("abc" != value) {
return 'validation failed';
} else {
return true;

I am not able to validate this text field.

Can I use isValid with text fields? I dint get any example or text explaining its usage.
If any one has links to good tutorials for ExtJS3.4, please let me know.

14 Nov 2011, 7:06 AM
<script language="javascript">
Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
Ext.onReady(function() {

Ext.apply(Ext.form.VTypes, {
Nospace: function(v) {
return /^[^\s]*$/i.test(v);
NospaceText: "Must not contain spaces",
NospaceMask: /[^\s]/i

new Ext.Window({
width: 500,
height: 400,
modal: true,
title: 'Testing',
items: [{
xtype: 'form',
labelWidth: 85,
border: false,
defaults: {
anchor: '-20'
items: [{
xtype: 'textfield',
fieldLabel: 'Wes Test',
name: 'wes',
hiddenName: 'wes',
vtype: 'Nospace',
validator: function(v) {
if (v === "abc") {
return "No abc's.";
return true;

Looks like it needs to be in a form, I've got both custom validator and a vtype and I'm seeing good results here. Take some time to look over the vtypes, enjoy!

15 Nov 2011, 11:39 PM
I did it using Validator itself. I am stuck at requirement where i need to validate textfield content when mouse is clicked outside the textfield.

c.on('mouseout', function (group) {
return function (f) {
alert("mouse out" + f.getValue());
}(group), this);
I am not able to work it out till now.
I guess mouseout was supported in ExtJS1.X.

Any one has tried this?

15 Nov 2011, 11:47 PM
Solved it with Blur. Had not expected meaning of blur to be opposite of Focus :)