在mysql中驗證電子郵件地址我已經通過有效的電子郵件地址,在MySQL存儲過程中沒有得到一個問題,這裏就是想發生:在存儲過程
DELIMITER go
Create procedure AddMessages(
Out MessageID tinyint(11),
IN iFirstName varchar(30),
IN iLastName varchar(30),
IN iTextBox varchar(400),
IN iEmailAddress varchar(30))
BEGIN
/*declaring local variable*/
If(iFirstName='') then
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Fill out the First Name';
Elseif(iLastName='') then
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Fill out the Last Name';
Elseif(iTextBox='') then
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Fill out the Message Box';
Elseif(iEmailAddress='') then
SIGNAL SQLSTATE '45000'
/* Checking if email address is not valid*/
SET MESSAGE_TEXT = 'Fill out the Email Address';
Elseif(iEmailaddress!='^[a-zA-Z0-9][a-zA-Z0-9._-]*@[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,4}$') then
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Please enter the correct email address'
;
Else
/* insert the messages*/
insert into Messages(
FirstName,
LastName,
Messagetextbox,
EmailAddress
)
Values
(
iFirstName,
iLastName ,
iTextBox ,
iEmailAddress
);
set MessageID = last_insert_id();
end if;
End
當我用
測試它set @new_id = null;
call AddMessages(@new_id,'Jamie','Jones','Hello','[email protected]');
select @new_id;
我是,我一直得到消息,說請 輸入正確的郵箱地址,我已經測試了不使用 @
和它的作品,但由於某種原因,驗證電子郵件蘇結果ppose不通過 顯示相同的消息。
您不能使用'!='進行正則表達式匹配。使用'IF iEmailaddress NOT RLIKE'...'' – Barmar
'='和'!='做精確的字符串匹配,而不是正則表達式。 – Barmar
請加**,請**允許超過30個字符的電子郵件地址。由於「david.jones @ corporationlatetotheparty.com」不是一個不尋常的地址,你會看到很多人碰到這個限制。使用'VARCHAR(255)'作爲任何通用文本字段,除非你有一個非常有說服力的理由來改變默認值。 – tadman