Validate space allowed in text rule

I created a new validate rule to allow spaces in a name field, and then I have an activity later that strips out the space when its time to send the data to a 3rd party through MQ-Series.

My question is how can I also make sure that the value entered are just letters.

Here is the java I have now that allows me to use a space in a name field.

[code]for (int pos = 0,len = theValue.length(); pos < len; ++pos) {
if ((! Character.isLetter(theValue.charAt(pos)))) {

if ((theValue.charAt(pos)==' ') || (theValue.charAt(pos)!=' ')) {
//System.out.println("Continue parsing");
} else {
return false ;

return true;[/code]

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.


Keep up to date on this post and subscribe to comments

December 23, 2009 - 4:40pm

Try this code...

var tmp = str.charAt(i);
if (!(isNaN(tmp) || (tmp==" "))) // checks for letters only if it is not a number / not space
if(toAscii(tmp) <=87 && toAscii(tmp) >=61)
return true; //Lower Case alphabet
else if(toAscii(tmp) <=67 && toAscii(tmp) >=41)
return true; //Upper Case alphabet
return flase; //special characters and others

Hope this helps... (Plz. check the ascii codes for alphabets again before using the above specified codes)

December 24, 2009 - 6:08am

its a very old post , even though the solution will help others so here is my code for this topic

for (int pos = 0,len = theValue.length(); pos < len; ++pos)
if (! ((Character.isLetter(theValue.charAt(pos))) || (theValue.charAt(pos)==' ')))
return false;
return true;

checking its a letter or space in the IF condition. apart from that for any special characters and numbers it will return false .



December 8, 2008 - 2:58pm

If you want remove space use the replaceAll method and apply the same.

December 9, 2008 - 9:27am

I have that part all set. My question is how can I make the code I attached above, also make sure that the values entered in that field are letter?


March 5, 2009 - 3:30am


In inner if block of spaces checking, if you want to check only space charecter you can convert toAscii() to convert into ascii value and check whether value is equals 32.

for example:

ascValue= toAscii(heValue.charAt(pos));--- function to convert is may not be same but look at context.

if(ascValue == 32) is true its definitely space charecter.

I think it might be helpful.

February 6, 2009 - 2:46pm

There is a library function @trim(str) to remove the whitespace. The argument str is the property you want to remove the whitespace from, for example, @trim(theValue);

Hope this helps

(Edit - my apologies. @trim() will remove leading and trailing whitespace. For whitespace within the string, initialize a regular expressions object (class Regex) with \s as its pattern to match, and use replaceAll() with "" representing the string to replace the whitespace with - you can Google search the Java API to view many examples)