MySQL Forums
Forum List  »  General

How to force a varchar number into a string?
Posted by: Zubi Mondragon
Date: February 13, 2015 08:47AM

Hello,

I'm doing a program in which you can reset a users password. This password needs to contain enlist one number in order to be "TRUE" among others (which are already done).

I have been looking for information about how to accomplish this task but my efforts haven't get me a solution.

I have found things about "rtrim" (which I think have nothing to do with what I'm trying), REGEXP_LIKE (could it be that the "like" is only for Oracle?).

Before I post the function know that this one serves no purpose but my own learning. Basically, I'm quite new at this.

Here goes the function:

delimiter //

drop function if exists login;

Create Function login (nombreusuario varchar(20), password varchar (10), repite varchar (10), vieja varchar (10))

Returns boolean no SQL

begin
/* Comparar los valores nombre y password con los reales */
declare comparacion varchar(30);
declare compa varchar(30);
set comparacion = (SELECT nombre
FROM usuarios
WHERE (nombre = nombreusuario)) ;
set compa = (SELECT contrasena
FROM usuarios
WHERE (nombre = nombreusuario));

if (comparacion = nombreusuario) and (compa = vieja) and length(password)>=6 and (password = repite) then

/* Hacer el UPDATE */
UPDATE usuarios
SET contrasena = password
WHERE nombre = nombreusuario;
/*Como es verdadero devuelve verdadero */
Return TRUE;
else
Return FALSE ;
end if;
end
//

delimiter ;

...........

I have try the next modification on the "if" line:

if (comparacion = nombreusuario) and (compa = vieja) and length(password)>=6 and REGEXP_LIKE (password, '[0-9]') and (password = repite) then

But it comes up with this error when I try to use the function:

ERROR 1305 (42000): FUNCTION incidencias.REGEXP_LIKE does not exist

What should I add into the if line to force a number on the password?

Thank you very much for your time.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.