jeudi 10 août 2023

I want to check whether name contains any special character or number in Ruby

This is code -

def username_chk(str)
     if str.length <=20         
        if str=~/^[a-zA-Z\\s]+$/
        puts "Invalid User name"
        else
        puts str
       end  
     else puts"User name can contain Max 20 character"
     end
  end   
      username_chk("Mark ju09")  

it's not working. I also tried:

str=~/[a-zA-Z]+\\.?/

str=~/^[a-zA-Z\s]+$/ this expression working fine in java using Pattern

Aucun commentaire:

Enregistrer un commentaire