Begin a validation library – form validation

In part to help other developers, and in part so that I don’t forget, I’ll post the beginnings of a Titanium Studio form validation library. This is what I created today.

//TEST FIELDS FOR NUMBER CHARACTERS
var hasNumbers = /[0-9]+(?:\.[0-9]*)?/;

var testFields = [ADD FIELD NAMES LIST HERE];

var hasNumberAlert = Titanium.UI.createAlertDialog({
title : ‘Attention:’,
message : ‘Fields cannot contain numbers.’
});

for(var i = 0, j = testFields.length; i < j; i++) {
if(hasNumbers.test(testFields[i])) {
hasNumberAlert.show();
noNumbers = false;
break;
}
}
// VALIDATE INPUT
if(noNumbers === true) {
Titanium.UI.window.open();
}
});

As always, feel free to post comments on ways to improve this code or your questions here.

Happy coding.

Leave a comment

Filed under iOS SDK, Javascript, Software, Titanium Studio

Leave a comment