NEWBY: How to reconize a numeric or alphabetic entry??

Well this is the question that i have.
I’m trying to make a global search field.
In this search field we could enter a numbers o alphanumeric chars. Numbers chars, could be a DATE or ID. So, the routine need be intelligent to recognize both numeric types of that fields (DATE / ID) and additionally, know if a char entry.
How can i do that?
Thanks for your help and sorry for my english :oops:

This is my routine right know:

/**
 * @properties={typeid:35,uuid:"f433f666-0c01-470c-a646-2a31f6337615",variableType:4}
 */
// var _recno = 0;

/**
 * @properties={typeid:35,uuid:"724135a7-b78a-466e-8e89-57e350291b60"}
 */
var _searchField = '';

/**
 * @properties={typeid:24,uuid:"c7786092-2f3c-45c2-84b9-03b69748c73c"}
 */
function ejecuta_busqueda()
{
	databaseManager.setAutoSave(false)
	foundset.loadAllRecords()
	var _nr = 0;
		if (foundset.find())
		{
			application.output(_searchField)
			if (_searchField)							// Si el campo _searchField tiene algo hacer:
				{
					apellido = "#%" + _searchField + "%"		// asigno a la variable de "tab.pacientes.apellido", el contenido del campo de búsqueda _searchField
					foundset.newRecord(false)				// ejecuto la búsqueda con false para que me muestre todas las coincidencias
					nombre   = "#%" + _searchField + "%"		// asigno a la variable de "tab.pacientes.nombre", el contenido del campo de búsqueda _searchField	
					foundset.newRecord(false)				// ejecuto la búsqueda con false para que me muestre todas las coincidencias
//					fecha    = "#%" + _searchField + "%"		// asigno a la variable de "tab.pacientes.fecha", el contenido del campo de búsqueda _searchField
//					foundset.newRecord(false)				// ejecuto la búsqueda con false para que me muestre todas las coincidencias
				}
				else
				{
					fecha 	 = '#' + _searchField
					foundset.newRecord(false)					// ejecuto la búsqueda con false para que me muestre todas las coincidencias
				}
			else
			{
				apellido = null
				nombre = null
				fecha    = null
			}
			_nr = foundset.search(true,false) 
//								// true en el primer parametro = si tenias un busqueda anterior, borrarla
//								// false en el segundo parametro = concidencias no exactas
//			application.output(_nr);		
		}
}

/**
 * @properties={typeid:24,uuid:"fa0fb8eb-8e42-4e1b-b638-452fe141e72d"}
 */
function limpia_filtro()
{
	application.output('Filtro eliminado...')
	foundset.loadAllRecords();
	_searchField = null;
}

Use the ‘typeof()’ method located in the JSLib under Special Operators. It will return the object type as follows:

Returns the type of the given object, one of these get returned: number, string, boolean, object, function, undefined.

I hope this helps!

FYI :

And what will the null value return ?? Answer : Object

Regards,

I imagine though that you’ll want to determine whether it is a date (say dd/mm/yyyy), a number containing only numbers or alphabetic characters as if it is a search field presumably you do different things depending on the type of value it is. To do that you’ll probably need to run some regular expression (match or search under JS Lib/String) to check, for instance, if the date is properly formatted or there are a mix of characters when it should just be one or the other (numbers or letters).

Thanks for yours answers, but i’m not clear yet :(

How to say this:

if (typeof(_searchField) = A STRING)
{
bla,bla…
}
else
{
bla, bla…
}

Explain me easy, please, like a little boy… I’m a newbie :roll:

Like so:

if ( typeof( _searchField ) == 'string' )

Check our the Servoy Wiki for more examples:

http://wiki.servoy.com/display/Serv51/Special+Operators

I hope this helps!

kwpsd:
Like so:

Unfortunately that will not work. Because the user input is entered in a text field, the type of the input will always be “string”.

I think you should use a couple of regular expressions to recognize numbers and dates and otherwise default to string, like this:

if (/^\d*$/.test(_searchField)) { //number
	...
} else if (/^\d{2}.\d{2}.\d{4}$/.test(_searchField)) { //date
	...
} else { //string
	...
}

If you want to know more about regular expressions, here is a small tutorial.

Joas, yes this is a one way to do what i want :)

But i’d found other way using isNaN() :D

// ej. using isNaN() function

var _searchfield = 99

if (!isNaN(_searchfield))
{
do something
}
else
{
do anotherthing
}

Well, thanks for all yours answers. I appreciate your help :)