Monthly Archives: September 2012

Using RegExp to make field validation easier

There is alot of ways to validate fields. But if you ask me validating thru regular expression is very powerful because you can test for patterns in strings. You can test for valid email adresses, phone numbers or your required passwords.

Because regular expressions can be tested both on the client and the server using almost the same code you can do tests on the client side without doing round trips to the server when the user exits a field or perhaps while the user are typing.

Lets look at an example of an regexp

[a-z]+

This will check that the tested string contains letters in the interval a-z

(\d{5})

The above code will test so the string is five numbers.

This is very helpful because then you could test for a password pattern

((?=.*\d)(?=.*[a-z])(?=.*[A-Z]))

This will then test the string to contain a digit, a lowercase and an uppercase letter. Imagine testing this some other way, no thanks. To complete this we also need to test for length and that we do by adding this to the line .{8,14} this will test that the string is 8 to 14 letters long. So the complete string is then

((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,14})

This seams complicated you might say, Yes regexp can be complicated but then we have great resources online to just copy and paste regexp from. But test the regexp you copy from the web, they might not do what you want them to do 😉

The best regexp tester that I have found is Rubular

How to use Regexp with old school Domino and XPages

How do you use this in Domino if you haven’t moved over to XPages yet, you could use this in client side javascript. And if you have moved over to XPages you can use this in Client side JS, Serverside JS and with a expression validator. I’m going to show you all these ways to validate.

1. Client side JS validation using RegExp

var field=document.getElementById("YOURFIELDNAME");
var data=field.value;
var re=/\d+/
if(re.test(data)){
   alert("Valid");
}else{
   alert("Not Valid");
}

2. Serverside javascript

The first Two lines changes from the client side script and also you need to write what should happen if the validation is true or not.

var inputText1= getComponent("inputText1");
var data=inputText1.getValueAsString()

var re=/\d+/
if(re.test(data)){
//do some stuff
}else{
//Do other stuff
}

3. validateExpression validator

The only thing diffrent in this validator than number 2 is that you return true or false when validation is done.

4. validateConstrain validator

This validator is used if you want to do a complete match of the value in the field using regular expression. My suggestion is that you start the string with ^( write you expression and end with )$ because then it’s easy to use a regexp tester when testing your regular expression this will tell the regexp engine that the string must validate as a line of text.

Update:

Check out this great post about how to creat regex strings directly in the designer.

http://www.intec.co.uk/test-your-regular-expressions-in-domino-designer/#comment-1498

Another XPageDeveloper.com Utility – Client Killer

Tired of killing the Notes client using the command line?

Client killer is the solution for you, a NSD.exe GUI that will find your Notes install folder and with a single click kill the notes client.

Hopefully you will never need to use it but if you do, get your free copy today 

Download Client Killer

nsd.exe high cpu fix run Client Killer

Designer Memory Configurator 1.1 update

The utility is updated to version 1.1 after a comment from a user that the memory option of 2048mb doesn’t work. So that one is removed as an option in the utility.

enjoy

Download it using the link below

–>>> Designer Memory Configurator

Domino Designer Memory Configurator is here

Do you want more speed in Domino Designer?

Do you want to configure you designer memory but always forget where to do it?

Did you know that everytime you add a Fixpack of the designer the memory is reseted ?

Now this is no problem just use Designer Memory configurator and with 2 click your memory is increased to the level you need.  

Download it using the link below

–>>> Designer Memory Configurator

If you every used .copytodatabase with a replicated or clustered Domino

I had a strange problem with documents that disappears in a replicated or clustered environment.

A more deep investigation lead to the discovery of deletion stubbs being created days/weeks/months before the document even was created, Strange. Documents getting create date the same as the original document.

But then a discovery was made .copytodatabase creates the same UNID everytime if the original document isn’t in the database. OK who cares the document isn’t in the database and no other document has that UNID. So far so good, but if you copy the document delete the new document in the new database. And copy it again, it gets the same UNID anyway. OK you might say, do this matter.

YES

It’s overwriting the deletion stubb on the destination database. If this database is in a clustered or replicated environment this will give your very very strange results. Documents disappearing, One minute they are there the next the documents are gone. 

There is a notes.ini param that fixes the problem, but there is nothing in the documentation. And do we need a notes.ini to fix a bug? It should be the other way around if you built an application that uses a functionality based on a bug then you should need to apply the notes.ini param not the other way around. 

To fix the problem apply the notes.ini param where your code runs client/server and you need to restart after applying.

CopyToDatabase_New_UNID=1

There is some other workarounds, one is creating a new document and using copyallitems. And the other one is copying the document two times but both these workarounds will give you problems if your document is large. So I would recommend the notes.ini param. 

This problem should only affect LotusScipt code but after trying it out it works the same in XPages also.