providers/validate: Add more functions
This commit is contained in:
		
							parent
							
								
									a7e8c337db
								
							
						
					
					
						commit
						876c7d1a1b
					
				@ -1,6 +1,7 @@
 | 
			
		||||
package validate
 | 
			
		||||
 | 
			
		||||
import "regexp"
 | 
			
		||||
import "unicode"
 | 
			
		||||
import "html/template"
 | 
			
		||||
import "git.tebibyte.media/sashakoshka/step"
 | 
			
		||||
 | 
			
		||||
@ -17,6 +18,7 @@ func (this *Provider) Package () string {
 | 
			
		||||
	return "validate"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Configure fulfills the step.Configurable interface.
 | 
			
		||||
func (this *Provider) Configure (config step.Meta) error {
 | 
			
		||||
	emailRegexpText := config.Get("validate.email-regexp")
 | 
			
		||||
	this.emailRegexp = nil
 | 
			
		||||
@ -31,8 +33,10 @@ func (this *Provider) Configure (config step.Meta) error {
 | 
			
		||||
// FuncMap fulfills the step.FuncProvider interface.
 | 
			
		||||
func (this *Provider) FuncMap () template.FuncMap {
 | 
			
		||||
	return template.FuncMap {
 | 
			
		||||
		"isEmail": this.funcIsEmail,
 | 
			
		||||
		"inRange": this.funcInRange,
 | 
			
		||||
		"isEmail":    this.funcIsEmail,
 | 
			
		||||
		"isPrint":    this.funcIsPrint,
 | 
			
		||||
		"inRange":    this.funcInRange,
 | 
			
		||||
		"strInRange": this.funcStrInRange,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -42,6 +46,17 @@ func (this *Provider) funcIsEmail (input string) bool {
 | 
			
		||||
	return emailRegexp.Match([]byte(input))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Provider) funcIsPrint (input string) bool {
 | 
			
		||||
	for _, run := range input {
 | 
			
		||||
		if !unicode.IsPrint(run) { return false }
 | 
			
		||||
	}
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Provider) funcInRange (min, max, value int) bool {
 | 
			
		||||
	return value >= min && value <= max
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Provider) funcStrInRange (min, max int, value string) bool {
 | 
			
		||||
	return len(value) >= min && len(value) <= max
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user