SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION [dbo].[f_verify_name] 
(
	@name as ais_name
)  
RETURNS BIT AS  
BEGIN 


	/*
	vérifier que la valeur de la chaîne name contient uniquement des caractères a-z, A-Z, 0-9 et _
	*/

	declare	@position int,
		@ascii int

	set @position = 0

	while (@position < len(@name))
	begin
		set @ascii = ascii( substring(@name, @position + 1, 1))

		if	(
					@ascii = 95									-- "_"
				or	( @ascii >= 48 and @ascii <= 57)			-- 0..9
				or  ( @ascii >= 65 and @ascii <= 90)			-- A..Z
				or	( @ascii >= 97 and @ascii <= 122)			-- a..z
			)

		begin
			set @position = @position + 1
		end
		else
		begin
			return 0
		end

	end

	return 1
		
	

END




GO
