Login Register

ValidationTextBox and regular expressions....Help!

Hi!

I'm having some trouble with the programmatic creation ov a dijit.form.ValidationTextBox:
I'm currently wondering why this doesn't work:

var validationBox = new dijit.form.ValidationTextBox({
        regExp: "[\w]+",
        required: true,
        invalidMessage: "regexp [\w]+ not fulfilled...."
},dojo.byId("tmpTagContainer"));

The problem seems to be the given Regular expression. The source file of the ValidationTextBox states, that the regular expression needs to be a string. The validation of the entered string always fails.

	
		ValidationTextBox Demo
		
	    
	        @import "../lib/dijit/themes/tundra/tundra.css";
	        @import "../lib/dojo/1.0.0/dojo/resources/dojo.css"
	    
		
	    
	    
		
	       dojo.require("dojo.parser");
	       dojo.require("dijit.form.ValidationTextBox");
	    
		
		
		   dojo.addOnLoad(function(){
				var validationBox = new dijit.form.ValidationTextBox({
					regExp: "[\w]+",
					required: true,
					invalidMessage: "regexp [\w]+ not fulfilled...."
				},dojo.byId("tmpTagContainer"));
		   });
			
		
	
	
		

Whereas the html-inline creation by doing the following works:

<input id="q22" type="text" name="phone" class="medium" value="someTestString"
        dojoType="dijit.form.ValidationTextBox"
        regExp="[\w]+"
        required="true"
        invalidMessage="Invalid Non-Space Text.">

Cheers,
rotorhead

in your programatic example,

in your programatic example, the \w is getting parsed, so you need to escape the \ preceding the w so it gets sent to the widget.

var foo = new dijit.form.ValidatonTextBox({
    regExp: "[\\w]+",
    ...
});
foo.startup();

worked for me.

Great!

Hi Dante!

Ohh, damn....why didn't I see that? Thanks a lot!

Cheers,
rotorhead