pub fn allow_numbers_only(sample:&str )->bool{
for c in sample.chars() {
let r = c.is_numeric();
match r {
true => {continue;},
false=> return false,
}
}
true
}
pub fn allow_alphanumeric_only(sample:&str )->bool{
for c in sample.chars() {
let r = c.is_alphanumeric();
match r {
true=> {},
false=> return false,
}
}
true
}
pub fn allow_alphabets_only( sample:&str )->bool{
for c in sample.chars() {
let r = c.is_alphabetic();
match r {
true=> {},
false=> return false,
}
}
true
}
pub fn get_alphabets(sample:&str )->String{
let mut alphabets = String::from("");
for c in sample.chars() {
let r = c.is_alphabetic();
match r {
true=> {alphabets.push(c)},
false=> {},
}
}
alphabets
}
pub fn get_numbers(sample: &str)->String{
let mut numbers = String::from("");
for c in sample.chars() {
let r = c.is_numeric();
match r {
true=> {numbers.push(c)},
false=> {},
}
}
numbers
}
pub fn get_alphanumeric(sample:&str )->String{
let mut alphanumeric = String::from("");
for c in sample.chars() {
let r = c.is_alphanumeric();
match r {
true=> {alphanumeric.push(c)},
false=> {},
}
}
alphanumeric
}
pub fn get_non_alphabets(sample:&str )->String{
let mut non_alphabets = String::from("");
for c in sample.chars() {
let r = !c.is_alphabetic(); match r {
true=> {non_alphabets.push(c)},
false=> {},
}
}
non_alphabets
}
pub fn get_non_numbers(sample:&str )->String{
let mut numbers = String::from("");
for c in sample.chars() {
let r = !c.is_numeric();
match r {
true=> {numbers.push(c)},
false=> {},
}
}
numbers
}
pub fn get_non_alphanumeric(sample:&str )->String{
let mut non_alphanumeric = String::from("");
for c in sample.chars() {
let r = !c.is_alphanumeric();
match r {
true=> {non_alphanumeric.push(c)},
false=> {},
}
}
non_alphanumeric
}
pub fn numbers_with_symbols(sample:&str,allowed_symbols:&str)->bool{
let just_numbers = get_numbers(&sample);
let just_symbols = remove_chars(&sample , &just_numbers);
let result = check_string_for_allowed_chars(&just_symbols,&allowed_symbols);
result
}
pub fn alphabets_with_symbols( sample:&str,allowed_symbols:&str )->bool{
let non_alpha = get_non_alphabets(&sample);
let result = check_string_for_allowed_chars
(&non_alpha,&allowed_symbols);
result
}
pub fn alphanumeric_with_symbols( sample:&str ,allowed_symbols:&str )->bool{
let non_alpha_num = get_non_alphanumeric(&sample);
let result = check_string_for_allowed_chars
(&non_alpha_num,&allowed_symbols);
result
}
pub fn no_caps( sample:&str )->bool{
for i in sample.chars(){
if i.is_ascii_uppercase() {return false;}
}
true
}
pub fn only_caps(sample:&str)->bool{
for i in sample.chars(){
if !i.is_ascii_uppercase() {return false}
}
true
}
pub fn begin_with( sample:&str,begin_char:char )->bool{
let first = sample.chars().nth(0);
match first {
Some(l)=>{
if l == begin_char {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn end_with( sample:&str,end_char:char )->bool{
let last = sample.chars().rev().nth(0);
match last {
Some(l)=>{
if l == end_char {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn begin_with_number( sample:&str )->bool{
let first = sample.chars().nth(0);
match first {
Some(l)=>{
if l.is_numeric() {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn end_with_number( sample:&str )->bool{
let last = sample.chars().rev().nth(0);
match last {
Some(l)=>{
if l.is_numeric() {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn begin_with_alphabet( sample:&str )->bool{
let first = sample.chars().nth(0);
match first {
Some(l)=>{
if l.is_alphabetic() {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn end_with_alphabet( sample:&str )->bool{
let last = sample.chars().rev().nth(0);
match last {
Some(l)=>{
if l.is_alphabetic() {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn begin_with_alphanumeric( sample:&str )->bool{
let first = sample.chars().nth(0);
match first {
Some(l)=>{
if l.is_alphanumeric() {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn end_with_alphanumeric( sample:&str )->bool{
let last= sample.chars().rev().nth(0);
match last {
Some(l)=>{
if l.is_alphanumeric() {
return true
} else
{
return false
}
},
None=>{
return false;
}
}
}
pub fn string_to_vec (incomming:&String)->Vec<char>{
let mut chars:Vec<char> = Vec::new();
for i in incomming.chars() {
chars.push(i);
}
chars
}
pub fn check_string_for_allowed_chars(data:&str,allowed_chars:&str)->bool{
for i in data.chars(){
match allowed_chars.contains(i){
true=> {},
false=> {return false}
}
}
true
}
pub fn remove_chars(sample:&str,subtract:&str)->String{
let mut result:String = String::from("");
for i in sample.chars(){
if !subtract.contains(i){
let j = i.clone();
result.push(j);
}
}
result
}