Skip to content

Commit c40a0e2

Browse files
committed
Add string find validations
1 parent 87c154e commit c40a0e2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Inp.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,39 @@ public function equal($str): bool
492492
return ($this->value === $str);
493493
}
494494

495+
/**
496+
* Checks if a string contains a given substring
497+
*
498+
* @param string $needle
499+
* @return bool
500+
*/
501+
public function contains(string $needle): bool
502+
{
503+
return str_contains($this->value, $needle);
504+
}
505+
506+
/**
507+
* Checks if a string starts with a given substring
508+
*
509+
* @param string $needle
510+
* @return bool
511+
*/
512+
public function startsWith(string $needle): bool
513+
{
514+
return str_starts_with($this->value, $needle);
515+
}
516+
517+
/**
518+
* Checks if a string ends with a given substring
519+
*
520+
* @param string $needle
521+
* @return bool
522+
*/
523+
public function endsWith(string $needle): bool
524+
{
525+
return str_ends_with($this->value, $needle);
526+
}
527+
495528
/**
496529
* IF value equals to param
497530
* @param $str

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ Inp::value("Lorem ipsum dolor")->equal("Lorem ipsum dolor");
5757
```php
5858
Inp::value("Lorem ipsum dolor")->notEqual("Lorem ipsum");
5959
```
60+
- **Contains**:
61+
```php
62+
Inp::value("Lorem ipsum dolor")->contains("ipsum");
63+
```
64+
- **Starts with**:
65+
```php
66+
Inp::value("Lorem ipsum dolor")->startsWith("Lorem");
67+
```
68+
- **Ends with**:
69+
```php
70+
Inp::value("Lorem ipsum dolor")->endsWith("dolor");
71+
```
6072

6173
### Validate if it's a valid email
6274
```php

0 commit comments

Comments
 (0)