我的Laravel规则和正则表达式操作有一个小问题:
基本上规则就是这样一个数组:
'room'=>'required|alpha_num|min:2|max:10',
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是使用正则表达式和| (或)运营商,例如:
'cid'=>'required|regex:/^((comp)|(soen)|(engr)|(elec))\d{3}$/i',
Run Code Online (Sandbox Code Playgroud)
我收到服务器错误说:
ErrorException
preg_match(): No ending delimiter '/' found
Run Code Online (Sandbox Code Playgroud)
我猜这preg_match是在第一个|内部停止/.../.
反正有没有写上面的代码使它工作?
完整代码:
public static $rules = array(
'cid' => array('required', 'regex:/^((comp)|(soen)|(engr)|(elec))\d{3}$/i'),
'description'=>'required|regex:/^[A-Za-z \t]*$/i|min:3|unique:courses',
'credits'=>'required|regex:/^\d+(\.\d)?$/'
);
Run Code Online (Sandbox Code Playgroud) 我的代码遇到了一个小问题.出于某种原因,当我尝试使用下面的代码抛出一个字符串时,我在visual studio中出错了.
#include <string>
#include <iostream>
using namespace std;
int main()
{
char input;
cout << "\n\nWould you like to input? (y/n): ";
cin >> input;
input = tolower(input);
try
{
if (input != 'y')
{
throw ("exception ! error");
}
}
catch (string e)
{
cout << e << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
错误:

我的 Android 代码有一个小问题。这是我第一次使用画布,我想为其设置图像但保留某种类型的纵横比。
这就是我现在正在做的事情,这将图像完全映射到画布上。它将图像宽度-高度设置为画布宽度-高度。
Drawable drawable = image; // gets the image
drawable.SetBounds(0, 0, canvasWidth, canvasHeight);
drawable.Draw(canvas);
Run Code Online (Sandbox Code Playgroud)
这在某些设备上效果很好,但是当设备很大时,拉伸效果就很糟糕。我想以保持纵横比的方式设置边界。如果画布的宽度-高度不是相同的宽高比,它将尝试以宽高比填充画布,但可能会在 x 或 y 轴上留下一些空间。
int imgWidth = 500;
int imgHeight = 800;
Run Code Online (Sandbox Code Playgroud)
我想根据这些值将图像映射到画布上,并根据需要进行拉伸,但即使部分画布未填充,也保持此纵横比。
做这个的最好方式是什么 ?
谢谢
我正在做一个学校项目,我们必须提交一些单元测试示例。我阅读了很多教程,但无法理解如何使用它。
这是我下面的代码,
我正在尝试通过手动输入检查我的验证规则:
<?php
class Student {
public static $rules = array(
'username'=>'required|alpha_num|min:6',
'firstname'=>'required|alpha|min:2',
'lastname'=>'required|alpha|min:2',
'studentid'=>'numeric|min:7|unique:student',
'email'=>'required|email|unique:student',
'password'=>'required|alpha_num|between:6,12|confirmed',
'password_confirmation'=>'required|alpha_num|between:6,12'
);
}
class ChronosTest extends TestCase {
public function testUser()
{
$student = new Student;
//$student->username = "john433";
$validator = Validator::make(array("username"=>"john433", "firstname"=>"johne"), Student::$rules);
$this->assertTrue($validator->passes());
}
}
Run Code Online (Sandbox Code Playgroud)
每次我使用assertTrue时我都会得到这个:

(来源:4.ii.gl)
每次我使用assertFalse时我都会得到这个:

(来源:1.ii.gl)
我试图覆盖我的Android应用程序中的默认文本外观
这是我的styles.xml但它不起作用(对于textView,picker等...)
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="newTheme" parent="newTheme.Base"></style>
<style name="newTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
</style>
<style name="TextAppearance.Large" parent="newTheme">
<item name="android:textSize">11sp</item>
</style>
<style name="TextAppearance.Medium" parent="newTheme">
<item name="android:textSize">11sp</item>
</style>
<style name="TextAppearance.Small" parent="newTheme">
<item name="android:textSize">11sp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)