PDA

View Full Version : Validation of text field input can take _ or .



samarth
13 Jul 2012, 1:13 AM
Hi folks,
I am using extjs 3.4 i have a text field of user name which can contains _ or . in the user name. How to do this?
I have used this for now validating my text field.



Ext.form.VTypes.validNameVal = /^[0-9a-zA-Z_.]{1}[0-9a-zA-Z_.]+$/;
Ext.form.VTypes.validNameMask = /[0-9a-zA-Z\ ]/;
Ext.form.VTypes.validNameText = 'In-valid.Input';
Ext.form.VTypes.validName = function(v){
return Ext.form.VTypes.validNameVal.test(v);
};




It is taking numbers, alphabets and it is not taking blank space. How to add it can also contain _ or . in the user name field

sword-it
13 Jul 2012, 2:11 AM
Hi samarth,
Try the code give below:




{
xtype: 'textfield',
name: 'name',
regex:/^\s*[a-zA-Z0-9._\s]+\s*$/, // accept number,alphabet, .(dot) , _, and blank space.
fieldLabel: 'Name'
}



37139

samarth
13 Jul 2012, 2:17 AM
Hi sword,
It works well thanks for you kind reply. My requirement is it shouldn't take space and it can only take _ and . in the field. no other special characters

Thanks in advance


Hi samarth,
Try the code give below:




{
xtype: 'textfield',
name: 'name',
regex:/^\s*[a-zA-Z0-9._\s]+\s*$/, // accept number,alphabet, .(dot) , _, and blank space.
fieldLabel: 'Name'
}



37139

samarth
13 Jul 2012, 2:24 AM
hi sword
I replaced this line it worked well



regex:/^\s*[a-zA-Z0-9._]*$/,



Hi samarth,
Try the code give below:




{
xtype: 'textfield',
name: 'name',
regex:/^\s*[a-zA-Z0-9._\s]+\s*$/, // accept number,alphabet, .(dot) , _, and blank space.
fieldLabel: 'Name'
}



37139

sword-it
13 Jul 2012, 2:29 AM
Hi samarth,
Try this code below:

It will also prevent the blank space in the begining of textfield.



regex:/^[a-zA-Z0-9._]*$/

samarth
13 Jul 2012, 2:31 AM
Hi thanks sword for your kind help

Hi samarth,
Try this code below:

It will also prevent the blank space in the begining of textfield.



regex:/^[a-zA-Z0-9._]*$/